ChildOF Bug with run-time?

Hello all,

I come here today after over 5 hours of failing to debug this problem with my game.

To keep it short, I have a hand animation and a shotgun animation that I am playing at the same time. The shotgun animation also changes a childOf constraint which is connected to an empty that is parented to the IK bone of my rigs hand to simulate him grabbing and hold something.

It’s the way I learned originally to do it by following this tut:

The animation in the viewport plays perfectly:


but when I run the game and activate it with some code:

2 issues:

  1. The shotgun is not following the childOF constraint, but the animation is running as it tilts down a little as it is supposed to.

  2. The rig animation with the hands is looping forever, despite the action actuator being set to play mode as well as me including deactivates in my code for the actuators.

This is the code I am trying to use:

if Type == "dBSS" and holderCatch['Held'] == 0:
                
                weaponReact = holderCatch.actuators['WeaponReact'] #holderCatch is the object that is moused over
                weaponGrab = cont.actuators['WeaponGrab']
                weaponGrab.action = "Pickup_dBSS_Bhands" 
                weaponGrab.frameStart = 1
                weaponGrab.frameEnd = 36
                weaponReact.action = "dBSS_pickup_gun"
                weaponReact.frameStart = 1
                weaponReact.frameEnd = 12
                cont.activate(weaponGrab)
                cont.activate(weaponReact)
                cont.deactivate(weaponGrab)
                cont.deactivate(weaponReact)
                holderCatch['Held'] = 1

The python is connected to some keyboard and mouse sensors and then the two action actuators. It runs everything else as it should, and it throws no errors or warnings when I run and play the animations. The animations are even for sure hitting the deactivates, because the variable after them is updating.

The empty is parented to the correct bone with the armature setting in the object options panel as well. My other animations (walk, throw, jump) all work as supposed to as well.

Hopefully somebody can help with what they think could be causing this issue, as I have run out of ideas.
Thanks
-KB

I am not sure, but it looks like you Are activating and deactivating in the same frame,

second, why not parent a empty to a bone, then parent the gun to the bone?

I felt like the control of the grabbing was easier with the empty, but I just tested replacing the constraint target with the ik bone itself, and I am having the exact same results. It must be the constraint some how, or the animation is not playing correctly.

As for deac/ac same frame, I only added the deacs in because the hand animation was playing forever, however it did not solve my problem sadly.

Got any other ideas?

Hmm, I’d go for BPR’s suggestion.
place you gun at 0,0,0, add an empty at point zero. Parent the gun to the empty, parent the empty to the bone. That “should” solve your offset problem.

That is how I have it right now, and it is the same issue sadly.

Does the Empties scale/rot/loc matter at all? I scaled it down, but when I apply the transformations it just reverts to it’s original position.

Examining my shotgun closer I notice a rotation on one of the frames was not applied properly, so when I apply it and attempt to correct for rotation a bit, it adds an action frame for every single object in the scene, saying the gun is parented to all of them… I have never had so much trouble with such a simple animation!

Normally, both empty and gun shouldn’t have any scale, or animation, you may rotate the empty after parenting to the bone.

Hmm, I am all messed up because of the frame in which I did not notice it, however I am unsure if this is effecting the parent issue, as it would be moving at least a little if the parent was working, just with wrong scaling?

Maybe you/somebody could take a look and see what I cannot. I have been looking so long at it, I am not seeing the fixes.

The ChildOf constraint is not supposed to work at all in runtime. You could replace it with a Parent actuator.
I suggest to unparent the gun from the empty and parent the empty to your bone.
Move the empty so it is in his hand and let the gun be on the table.
Then, at runtime, at the right time of the animation, activate the parent actuator on the gun to parent it to the empty (maybe with a delay sensor)
I didn’t look at your file but I think it will work.

Awww yeah, thanks to the advice received, my parenting now works exactly as it should.

I had feared the childOf constraint was not active in BGE, but I was going to try it anyways. Now I know better.

All that is left is problem 2, the animation of the rig is just playing forever, rather than once. This is peculiar, because the action Act. of the gun and the rig are the exact same setup with the same play mode as confirmed by python.

Once I figure out a way to fix that as well, I will make sure to update my original post with a solution to the problems, since these kinds of issues seem to be common for people.

Of course! Open to suggestions on what i am doing wrong here. I think it must be my code, I tested it connected to a keyboard sensor and it worked fine. Somehow it is just running forever when it is attached to the python script.

To bump this thread back up.

It seems something is going wrong when I am parenting my empties to my rigs ik bone still. When parented, it displaces and rotates quite a bit. My rig has loc/rot/sca all applied, and the empty I am using is a brand new empty with all of those applied as well, and it is still seeing the displacement.

Anybody know whats up with this? Very frustrating.

Pictorial representation:


It does the same thing for the left ik bone as well with a different empty. The run-time now that I have altered it a little, plays as if the parent IS in the correct location.

I ended up parenting my weapon manager (a empty that spawns weapons) to a vertex in the hand,

that way they always match up, I am not sure if this is your current issue.

So what take a face or a vertex from the hand, separate it to it’s own mesh, then parent the empty/gun to that?

I tried that method out, it works in the viewport, but not in run-time for me.

no, select the gun empty, select the mesh you are going to parent it to, hit tab , select a verticy in the hand, hit ctrl+p

:smiley:

no need to make a separate mesh

I use this in my own game,

Ah of course, I don’t know why I did not think of that lol.

I am still curious behind the strange displacement of my parents in this situation. I just tried your method, works a lot better. One of the issues with some minor displacement that I am seeing is that I foolishly did not apply these hand empties in the rest mode, so when parented to the skin mesh it was a bit off.

Ugh, now to see if I can easily fix the parenting in this animation… or maybe sweep it under the carpet and just do it later.

Another question while we are talking about parents, do you (or anybody) know if the remove parent actuator is working in BGE? In the past, and right now I have tried to use it and it does nothing. Example, you can see the double barrel shotgun in the picture I posted a little up more. I have the shells parented to the barrel, then in my reload animation I want to end the parent relationship so when I tip the gun up, the fall out due to their own physics. However, I attempt the process, and the shells just sit there doing nothing.

I have had similar results in the past where it seems the parent bond is not broken. Am I doing something wrong I need to look back into fixing, or does it just not work in GE as a bug?

objects parented in the ui lose their dynamics

use addobject instead, and just have the shell disappear in the model and reappear when loaded

visibility actuator -> no collision shells +add shell on message

message----------and-------------property time=15
_________________--------------add shell
__________________--------------visibility = invisible

if time min:1 max:15-------------and----------time add -1

if time changed------and---------------------Visibility = Visible
if time=0------------/

I was afraid that was the case.

So then to show a full reload animation using the idea you have with just add remove I could do something very similar to what you suggest.

I will probs try first:

Delay once animations starts --> addObject (New shell) then endObject (old shell)
Delay again --> addObject (new new shells) to two empties parented to the hand
Delay third time till they are in right spot --> parentActuator and parent them back into position.
end animation

All of which triggered by an actuatorSensor which is looking for the actionActuator to be played.