In toying around with Animator component on a skinned mesh, I discovered that for some reason, when NOT using root motion (works fine otherwise) and switching the runtimeAnimatorController property via code somehow resets the entire player’s transform object (position and rotation) to where it was in the world when Play mode began.
The code for swithing used to be:
PlayerAnimator.runtimeAnimatorController = //new controller here
I managed to work around it using the following wrapper function:
Again, it used to be OK when I was using Root motion for the avatar’s locomotion, but I decided to switch root motion off and drive the player’s Rigidbody manually in order to have more control over what’s happening, since it’s going to be a relatively complex third person RPG.
Any ideas what’s causing this?
EDIT - Added velocity saving to the function as well.
bump got same issue. They change how the whole hierarchy updates when you change the controller (dont know why they did this)… pretty useless now…because the fix would be glitchy.
I believe this is an unintended bug. It’s weird how the skinned mesh resets to where it was when the scene began playing, not (0,0,0) as you would expect. You move your player’s starting point and it gets reset there.
Also, it seems my little workaround posted in the opening post is actually working rather nicely. Simply storing and restoring position and rotation appears to be enough. Physics look solid, no glitches, no unintended side effects.
Eh, we’re in game development. It’s part of the job description
Dunno about you, but the fact that I am switching animation controllers at runtime is already a workaround, to avoid having hundreds of animator parameters, spaghetti controller code, and spaghetti state machine.
Now I’ll have to workaround the jarring, non-interpolated animations when switching controllers.
After all that, I’m gonna have to workaround something else.
Your right but its a annoying new “feature” Thought i am happy with the performance in 5.5.1
I have seperated controller for each weapon type, to avoid the mess in the nod Mecnamim . I show you how it did this pretty clean with enums. I am also working on a RPG its all about flexibility and control right?
public void SetAnimationMode()
{
if (combatMode == Condition.Melee)
{
ChangeController(CharAniMelee);
}
else if (combatMode == Condition.Ranged)
{
ChangeController(CharAniRanged);
}
else if (combatMode == Condition.Ranged2Hand)
{
ChangeController(CharAniRanged2Hand);
}
else if (combatMode == Condition.Mount)
{
ChangeController(FlyStance);
}
else
{
ChangeController(CharAni_None);
}
// RefreshAniControllerContent ();
}
public void ChangeController(RuntimeAnimatorController Newctrl)
{
Vector3 position = Player.Script.transform.position;
Quaternion rotation = Player.Script.transform.rotation;
anim.runtimeAnimatorController = Newctrl;
Player.Script.transform.position = position;
Player.Script.transform.rotation = rotation;
}
Just so every one knows. This is not permanent fix for this bug, the bug must be fixed else i see no point on using a newer version of Unity Engine. This leads to all strange things and glitches where the object transform allaround the place and back on Animation controller change… Animation controller is a pretty core feature in Unity…
Well, I’d argue there’s some significantly worse stuff that needs fixing before this. It’s not deal breaking.
In my RPG, we started off by using a skeleton rig from Third Person Camera asset pack. It got significantly modified with weapon bones, entire animation control code re-written (physics driven instead of root motion etc).
Some of the work on that rig was done in 3DS Max by me. A friend who is also interested in animating does not have a Max licence, so he’s learning to use Blender (to be honest, Blender has way superior animation workflow).
When he exports an animation from Blender, it’s impossible to use “Copy Existing Avatar” from Rig tab in import animation (I mean, you can use it, but it just goes Gmod Idiot Box on you). It’s Created anew from import.
Here’s the kicker:
You cannot put his (Blender) animation into an Animator built from previous Avatar (made in Max). It just shows up blank (idle animation). You cannot mix animations with different avatars in one Animator controller. Sound somewhat logical, yes?
BUT, if you put his animation into a new Animator controller, and just switch the runtime animator controller via code, it auto-magically works! Animation looks correct, feels correct, skeleton and entire rig is correct. I dunno how, I dunno why.
Why can’t this “retargeting” logic be applied to “Copy Existing Avatar” workflow, I do not know.
When you import a new animation that has the same physics and structure as your old Avatar. you can copy that avatar to your new Humanoid skeleton it works just fine. You dont even need to import the mesh.
I haven’t tried with the new version yet, maybe i can’t do that any more ether. I really wonder why i upgrade in the first place…
Man i tell you, your fighting a war you can’t win… the bug war, featured by Unity. My bug report was moved to animations section so i guess this bug is part of the animation now. we suppose to warp to 0 now… /sarcasm off
This will always glitch nomatter how much you try to preserve data, you should see what one of my AI mob did when the controlller changed… Monster was like…“wtf is this player doing”… warping…glitches…I am not even talking about multiplayer issue this also effects. Maybe i should go back to legacy animation…
I just got this too. I submitted a bug report with a repro case. I doesn’t happen when I switch the runtimeAnimatorController, but if I switch it and then switch it back, my character instantly pops back to its starting position.
@Eudaimonium@Ironmax@kdgalla Also changing the avatar at runtime apparently doesn’t work. So how do we allow players to switch characters in the middle of the game? There are workarounds I suppose, but in my case it would be a nasty workaround given the way I currently have things set up (since I didn’t know about these bugs until now).