Forum rules - please read before posting.

Animating With Prefabs

edited June 2018 in Technical Q&A
Is it possible to animate prefabs that are child objects of player characters? In my scene, my player switches to a player character holding a gun (parented to his right hand). I want to animate this gun with an object: animate action, but I get an "Animator is not playing an AnimatorController" Warning message in the console.

I also cannot use the sound object attached to that model to play sounds, though I can get around that by having the sound object in the scene, so that's not a big deal.

Full version:

Animator is not playing an AnimatorController
UnityEngine.Animator:SetTrigger(String)
AC.AnimEngine_Mecanim:ActionAnimProcess(ActionAnim, Boolean) (at Assets/AdventureCreator/Scripts/Animation/AnimEngine_Mecanim.cs:616)
AC.AnimEngine_Mecanim:ActionAnimRun(ActionAnim) (at Assets/AdventureCreator/Scripts/Animation/AnimEngine_Mecanim.cs:571)
AC.ActionAnim:Run() (at Assets/AdventureCreator/Scripts/Actions/ActionAnim.cs:117)
AC.<RunAction>c__Iterator2:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:347)
UnityEngine.MonoBehaviour:StartCoroutine(String, Object)
AC.ActionList:ProcessAction(Int32) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:306)
AC.ActionList:ProcessActionEnd(ActionEnd, Int32, Boolean) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:522)
AC.ActionList:EndAction(Action) (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:440)
AC.<RunAction>c__Iterator2:MoveNext() (at Assets/AdventureCreator/Scripts/ActionList/ActionList.cs:409)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

I assigned the Animator to the Object Animate action by dragging the prefab into the field, and it recognized it's ConstantID. 

Is this just a Unity limitation?

Comments

  • It should work in theory, but there've been a few issues reported with more recent versions of Unity about Animators not being initialised when spawned at runtime.

    What's your version of Unity, and what is the state of the Animator in question?

    It may be possible to alternatively incorporate the animation into the root object's Animator using layers.
  • edited June 2018
    My Unity is 2017.1.

    I tried using the player character's animator and making a separate layer for the gun, but it just wouldn't play, with neither player animate or object animate (tried changing parameters as well as playing custom options).

    In the end, I've found a workaround (with the gun already present in the scene) by using object teleport and character hold object actions - within an action list that is also referenced by the inventory item combine action list, to check which scene we are in. 

    I also made use of Final IK's Interaction system (thanks for updating the wiki btw) to give it a bit more realism when picking the object up.

    Another workaround is to have an action list asset that handles the object transforms, with "Moveable" scripts on the moving pieces of the gun rather than using animation. In fact, I think that would have been less hassle than what I actually went with. :smile:
  • If there was an issue with sub-layer playback, was that with Unity or with AC?  If you changed the parameter values manually in the Animator component, did they play correctly?  If not, it's likely just a missed step in Unity - did you give the layer full weight?
  • I gave the layer full weight, no weight, half-weight, override, additive. I tried pretty much all options but it just wouldn't play.
    BUT  I noticed that, when I put another gun prefab instance in the scene by itself, and watched it in scene view - that actually animated, but not the one parented to the character's hand. I don't remember which option I used to get that going and I've now deleted that whole setup since I went with another solution, but I got the feeling I was close to figuring it out (obviously not close enough).
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.