Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Controlling a GameObject from a empty state

Discussion in 'Animation' started by HerbertSSchaefer, Jul 8, 2015.

  1. HerbertSSchaefer

    HerbertSSchaefer

    Joined:
    Oct 25, 2014
    Posts:
    7
    I have a GameObject that i need to control it's position in some animations, but in another i need to control via script.

    The problem is that Unity animator does not allow that, even if i remove any properties of the gameobject from a state it still keeps overrything my control. Apply root motion or any configuration does not help and i cannot use LateUpdate because the control is based on the state of the previous frame.

    The only way that works is animating a empty object and in the correct state of the anomator i make my gameobject follow this object (or parent him), with is not a good idea because a animator guy will be doing the final animation and it complicated its job because he cannot see the effect of the animation in the preview.

    Or i save the previous frame and use this to calculate the control, what is just busy work in a system that should not require this. Also requires me to change some scripts from another developer that are already working fine.

    Does anyone have a better idea before i give up in the Animator for good and do it old style in basically pure code?
     
  2. U-GeeN

    U-GeeN

    Joined:
    Mar 22, 2015
    Posts:
    95
    Yes this is a real problem. The animation allways writes values from the curves.
    The only workaround I use is deactivating the whole animator when I use script.
    You can do it even through an AnimationEvent.
    Build an extra State that deactivates the Animator and reactivate it when your Script is done.
     
  3. U-GeeN

    U-GeeN

    Joined:
    Mar 22, 2015
    Posts:
    95
    I just tested some better solution. You simply add an empty state with no animation.
    While in this state the object should respond to script.
    You're welcome
     
  4. HerbertSSchaefer

    HerbertSSchaefer

    Joined:
    Oct 25, 2014
    Posts:
    7
    Thanks for the reply compadre.

    But still will not work because in your first solution there's yet another animation where i need a curve of other objects and have control over my object, so deactivating the whole animator will also stop the other curves to play.

    And about the empty state, that's the problem, that's exactly what i am doing and the object still locks, even playing a animation that have no curves on it, even changing ther layer of the empty state, still locks the properties of the object. Maybe is the version of Unity that i am using (4.6.6, the team locked to this version for this project).

    I managed to find a "workaround", but is very fiddly. I've parented the object and i control the parent in the animation, when i have a animation that i need to control the object i unparent him. I also needed to put some events in the animation and also wait when it changes state and also wait 2 frames to control the object so it does not jump, but i managed it hehehehehe
     
  5. U-GeeN

    U-GeeN

    Joined:
    Mar 22, 2015
    Posts:
    95
    Thats probably the reason. It worked perfectly for me.
    Have you tried to make an extra animator for the scripting part and deactivating it?
    Sorry I couldn't help much.
    Good luck
     
  6. U-GeeN

    U-GeeN

    Joined:
    Mar 22, 2015
    Posts:
    95
    Now I got the same Problem as you.
    I decided to make a single Animator for my Player and place it on the top most GameObject of the player Prefab right next to Character Controller, NetworkIdentity and NetworkAnimator.
    Since only one NetworkIdentity should be used in a Network object and NetworkAnimator needs to have its Animation and NetworkIdentity in the same GameObject as well.
    Now my new created animator prevents Character Controller to move around the Player.
    So how is that supposed to work?
    Where should the components be to function correctly?