Game Development Community

Changing to a new animation

by Tony Pitman · in Torque X 3D · 12/11/2009 (10:28 pm) · 21 replies

I have a DTS model I created. When I look at it in ShowTool Pro both my Walk and Die animations work fine.

If I set my model to the walk animation when I start the model going it plays fine. If I then set my Die animation as the starting animation it works as well.

The problem I am having is when I start the Walk animation and then later try to change to the die animation.

Here is the code I use to set things up with a new model:

T3DAnimationComponent animationComponent = new T3DAnimationComponent();

// Add the animation component   
animationComponent.SceneGroupName = sceneComponent.SceneGroup;
newZombie.Components.AddComponent(animationComponent);

TorqueObjectDatabase.Instance.Register(newZombie);

// Walk Animation
TSAnimation animationWalk = new TSAnimation();
animationWalk.ThreadName = "ActionThread";
animationWalk.SequenceName = "walk";
animationWalk.Name = "Walk";
animationComponent.AddAnimation(animationWalk);

// Die Animation
TSAnimation animationDie = new TSAnimation();
animationDie.ThreadName = "ActionThread";
animationDie.SequenceName = "die";
animationDie.Name = "Die";
animationComponent.AddAnimation(animationDie);

zombieComponent._currentAnimationPlaying = CurrentAnimationPlaying.Walk;
zombieComponent._currentAnimation = (TSAnimation)animationComponent.GetAnimation("Walk");
zombieComponent._currentAnimation.Play();

Later I use this code to change to the Die animation:

_currentAnimation.Stop();
_currentAnimationPlaying = CurrentAnimationPlaying.Die;
_currentAnimation = (TSAnimation)_zombieAnimationComponent.GetAnimation("Die");
_currentAnimation.Play();

When I do this the eyes of my model move, but then model's skin itself doesn't move in the die animation it keeps using the walk animation. Then suddenly changes to the last frame of the die animation.

I must be calling something wrong. Any ideas?
Page «Previous 1 2
#1
12/12/2009 (12:04 am)
Hmm now animation is not my strong point, but I wonder if they're blended animations, ie mixing the two together, or whether one animated part wont play until the next is finished?
#2
12/12/2009 (12:06 am)
That may have something to do with it. I also found another problem with it and that is I have 4 objects that all were copied from the same template. The template did NOT have the animation on it. I add the animation component to the copies as they are made.

Well, when I switch the animation on one of the objects all of them switch (well, as well as they are switching).
#3
12/12/2009 (12:14 am)
The only thing I can see that you're doing different from the code in MovementComponent3D.cs is calling Stop(). I can't see why that would cause the issue, did you try it without calling stop() ?

I have yet to make an animated mesh, thought I did make one in max years ago.
#4
12/12/2009 (12:31 am)
Well, I figured out what it is, but not why or how to fix it.

It is not the stop call. In fact I had to remove that because it would ASSERT sometimes.

The problem is that I have more than one of this model at the same time. Somehow they mess each other up.

I tried just spawning a single copy and everything works great. That sucks because I want to have many of them. I could create individual objects with different names, but then I can make things as dynamic as I would like.

I seem to recall having a similar problem with straight XNA animation using the code I used to write the original Math Sniper game I did. Apparently you can't have more than one object based on the same source .DTS or .FBX object and have different animations running on them.
#5
12/12/2009 (2:49 am)
I understand what you're saying, but it would be silly if you couldn't do that. Most games have more than one of the same model, and I can't see the guys intentionally writing code to limit it in that way, so there must be a problem somewhere else. The xna animation demo was pretty simplistic.

Perhaps you need to change the animation thread dynamically every time you clone your object?
#6
12/12/2009 (2:40 pm)
I agree 100%. As you can see in my code above I call the animation thread "ActionThread". Is there anything special about that name? I got that from the FPS Demo. Can I just give each one a unique name maybe? What does that thread name have to do with anything?
#7
12/12/2009 (2:53 pm)
Well, I tried giving each object its own thread name and that didn't help. The common factor here is that they are all loading the same DTS file. If I make copies of the DTS file, put them all in the project and level xml file and then load each object from its own DTS file then everything works fine.
#8
12/12/2009 (8:30 pm)
You've copied the object, how did you set up your template? Did you set PoolWithComponents to true?
#9
12/12/2009 (8:46 pm)
PoolWithComponents is false
#10
12/12/2009 (10:44 pm)
try setting it to true.
#11
12/12/2009 (10:46 pm)
That should not help because I am not creating and deleting the objects. I create them and they hang around forever. I just move them back to the beginning of their path.

Will setting that change something else that will help somehow?
#12
12/12/2009 (11:46 pm)
I'm not 100% sure on that. What I'm looking for is to see if the cloned animation components are indeed seperate objects and not all pointing to the same reference. You can test that using .GetHashCode() on any object and do it in the debugger watch or use Debug.WriteLine().
#13
12/13/2009 (12:15 am)
I have output the hash codes for the T3DAnimationComponent, TSAnimation and the TSAnimation.Thread objects and they are all unique to each copy of the model.

I will keep outputing different ones. Are there particular objects other than those above that would cause problem if they were the same for all of the copies?
#14
12/13/2009 (12:26 am)
I think I figure out what is going on. I am not sure of my solution, however.

In the T3DTSRenderComponent the CopyTo function just sets the _shapeName and then sets the obj2.Shape to the Shape of the object being copied. What this does is share the shape with all copies.

I changed the CopyTo so that is uses obj2.ShapeName (note the capital letter and no _). This causes the shape to be reloaded and a new Shape object is created.

The next issue I then had was in the TorqueObject.TestCopy method it was failing because now the copies are not the same. I just commented out the call to TestCopy for the components and that fixed that.

With this setup now the animations all work as they should. So I know that I broke something when I commented out the TestCopy for the components, so how do I fix that? It must be that there is a setting somewhere that sets whether the shape needs to be the same on a copy or not. Where would that be?

Is this the right thing to do? I would guess there was a reason the shape was supposed to be shared, the problem is then the animations can't play independant of each other.
#15
12/13/2009 (12:33 am)
So I added [TorqueCloneIgnore] as an attribute to the Shape get;set; and that fixed it.

So is this something that GG should put into the main code or is this something that I just need?
#16
12/13/2009 (1:12 am)
Good job fixing it. I'm betting it's something the GG guys need to do. I know these guys are good at what they do but they doesn't mean they don't make mistakes. It's like my issue with disabling post processing effects and using particles causes an vertex buffer exception because once per frame, the vertices[0] of the graphics device wasn't being set to null. That's a bug. These guys are not perfect! Neither are we.

The point is, if you have to modify the engine to make your game work, well, thats why you have the source! You don't have to use the modified source for every other game you make.
#18
05/03/2010 (8:59 am)
Which class holds the _currentAnimation property?
#19
05/03/2010 (9:07 am)
Your own class holds that. If you look in my original code you can see it is my ZombieComponent class that holds it. Basically you keep track of the currently running animation so you can change it.
#20
05/03/2010 (9:45 am)
Where can I find the original code? Would very much like to take a look, thanks.
Page «Previous 1 2