Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Animate Object when its Animator is in different Gameobject

Discussion in 'Animation' started by arvrappps, Mar 26, 2017.

  1. arvrappps

    arvrappps

    Joined:
    Feb 12, 2017
    Posts:
    24
    I have 2 gameobjects A & B (to which i want to animate) in scene. If I attach animator component to both (individually) and make a state(a_anim & b_anim) with animation(a & b) then its working fine when I touch the object using Raycast)
    But I want to remove that Animator from that object.
    So for this I create a third empty game object Combined and add Animator component in it and made 2 states(a_anim & b_anim) for both the objects and assign animation (a to state a_anim AND b to state b_anim).
    Now when I touch the object in Animator window animation state is running(a_anim and b_anim) but actual animation on object is not working
    reference of animation(a & b) are not matchup with the objects A & B.
    GameObjects : A,B
    Animator : bothcombined
    animations a,b
    Animator States : a_anim & b_anim
    I want to attach these Animator states or Animation to the Objects A & B.
    SEE ATTACHED SCREENSHOTS BELOW : Working , Not working
    View attachment 224365 View attachment 224366
     
    Last edited: Mar 26, 2017
  2. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    194
    I'm unable to see the screenshots you posted, however, based on your description I think I know the issue. Unity's animations are based on a name based system that finds objects in the hierarchy of the object that owns that AnimatorController and Animations. So when you moved the AnimatorController to the "Combined" gameobject, Unity can't find the object you are intending to target and the animation fails. If you select the Combined gameobject in the hierarchy and open the Animation Window (Ctrl + 6 on PC/ CMD + 6 on Mac) you will probably see all the animated properties in bright yellow...this means that Unity can't resolve the path to the property.

    You will probably have to either rework your animations or create some type of control script that can pass messages down to the child AnimatorControllers.

    Cheers,
    TrickyHandz
     
  3. arvrappps

    arvrappps

    Joined:
    Feb 12, 2017
    Posts:
    24
    Thanks for reply... i hosted images (working & not_working)
    Yes you are right ..its showing Gameobject/component is missing.
    I'm newbie in unity..could you please tell me how to make new animations and link them to objects A & B or that script.
    Note : I'm doing all this i want to use LeanTouch script (lean Rotate - for rotating model using swipe in x/y/z direction) and I found it is not working until Animator component is removed/disabled from object/3d Model. Is there any workaround ?
     
    Last edited: Mar 26, 2017
  4. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    194
    I'm not familiar with Lean Touch, so I'm not going to be able to help you out with the best way to use it. However, I can say that Lean Touch probably trying to change the rotation of the object, which the animator will not allow you to do. I'm not sure of any workaround to it.

    Any object you want to be animated by a single controller would have to have a parent-child relationship. For the controller to be on the "Combined" gameObject, you would have to have your hierarchy look like this:

    ParentChildObjects.PNG

    Then you would have access to the animatable properties of both A and B in the Animation Window.

    When it comes to learning how to use the Animation workflow in Unity I would recommend starting with the Unity Learn topics here: https://unity3d.com/learn/tutorials/topics/animation
    Aside from that there is a lot to said for just experimenting.

    Cheers,

    TrickyHandz
     
  5. arvrappps

    arvrappps

    Joined:
    Feb 12, 2017
    Posts:
    24
    Hi,
    I made a parent-child relationship. But the same result ... in animator window everything is right..I saw the animation called and its working but actual 3D object is not animating..
    THIS TIME ANIMATON WINDOW DOESNOT HAVE ANY YELLOW / MISSING COMPONENTS
    Still animation is not working...only animator is working fine
    (
    actually animator is attached to combined so, animation changes the value of combined and not A & B. how to refrence A & B in combined)
    Please guide me how to do this

    Yes I want to have rotate script. on swipe but this animator component is breaking all flow
    Thanks for tutorial links.
     
    Last edited: Mar 27, 2017
  6. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    194
    There is always going to be issues with manipulating transforms through code while animations are also manipulating them. Could you perhaps upload a unity package with a scene that reproduces your issue? I can get a test project up this evening, but I would really need to see exactly what it is you are attempting to better help.

    Cheers,
    TrickyHandz
     
  7. arvrappps

    arvrappps

    Joined:
    Feb 12, 2017
    Posts:
    24
    if you are online u can take remote desktop my machine using teamviever...tell me when u r available (like 1 hour from now ...) due to difference in timezones
     
  8. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    194
    I won't be able to do any remote assistance. Is there any reason you wouldn't be able to upload a scene that shows the issue?

    Cheers,
    TrickyHandz
     
  9. arvrappps

    arvrappps

    Joined:
    Feb 12, 2017
    Posts:
    24
    OK... There is no problem..I think that approach is fast..but not a problem
    Will send you project package
    Thanks !
     
  10. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    194
    All animations in Unity work on name based paths to the properties. So, if you the animation came with the model, the instance of that model in the scene will have to have an Animator component for Unity to be able to find the properties that need to be animated.

    If you animate using the Animation Window, you always need to have the object with the animator as the "root" object in the animation. Again, this is all so that Unity can find the path to a property properly. There is no easy way to rework an animation asset to rename properties and it is highly discouraged to rename or move objects that are being animated because of the name-based paths used. I hope that all makes sense.

    Cheers,
    TrickyHandz
     
  11. arvrappps

    arvrappps

    Joined:
    Feb 12, 2017
    Posts:
    24
    Thanks !
    Now all is working ... I'm using Unity Remote4 for android and sometimes it detects touches sometimes not...now I build it to android device and everything works perfectly ( as needed).
    You always replied.Thanks for all your help and your suggestions.
    Have a nice day !
     
  12. arvrappps

    arvrappps

    Joined:
    Feb 12, 2017
    Posts:
    24
    Hi,
    I have two concentric box colliders on same game object. Outer box collider rotates the object(on swiping the screen) and inner box collider plays animation when We touch the screen.
    But When ray goes from my mobile screen to outer collider it destroys and not pass through that collider.
    Is there any way to do it.
    Thanks!
     
  13. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    194
    You might want to take this particular question to the scripting forum. Off-hand I would say that your script is calling Destroy() for you collider, when it should just be doing something along the lines of
    Code (csharp):
    1. collider.enabled = false
    Nested colliders can be a difficult thing to deal with, so the scripting forum is probably your best bet to solve this problem.

    Cheers,
    TrickyHandz
     
  14. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    194
    So, this one is more of scripting, but the approach I would take is to write a coroutine to handle it. Something like this assumes the objects are being instantiated from prefabs:
    Code (csharp):
    1. using System.Collections;
    2. using UnityEngine;
    3.  
    4. public ObjectSpawner : MonoBehaviour
    5. {
    6.     [SerializeField]
    7.     private GameObject particlePrefab;
    8.     [SerializeField]
    9.     private GameObject objectPrefab;
    10.     [SerializeField]
    11.     private float waitTime = 2f;
    12.  
    13.     private void Update()
    14.     {
    15.         // Replace this input code with the
    16.         // action that will trigger the spawning
    17.         if(Input.GetKeyUp(KeyCode.Space))
    18.         {
    19.             StartCoroutine(ShowObjects);
    20.         }
    21.     }
    22.  
    23.     private IEnumerator void ShowObjects()
    24.     {
    25.         // Instantiate the particles
    26.         Instantiate(particlePrefab);
    27.         // Wait for the amount of time set in
    28.         // the waitTime field
    29.         yield return new WaitForSeconds(waitTime);
    30.         // Spawn the object prefab and
    31.         // Destroy the particle system
    32.         Instantiate(objectPrefab);
    33.         Destroy(particles);
    34.     }
    35. }
    36.  
    Please note the above code is written without any testing in Unity, but it should give you the gist of what needs to happen. I would recommend looking at the scripting forums for ways to improve this, like using object pooling if you plan on doing a lot of this in your project.

    Cheers,

    TrickyHandz
     
  15. arvrappps

    arvrappps

    Joined:
    Feb 12, 2017
    Posts:
    24
    Thanks for reply...Today I have not checked ... But will give it a try tomorrow..
    Thanks !
     
  16. arvrappps

    arvrappps

    Joined:
    Feb 12, 2017
    Posts:
    24
  17. arvrappps

    arvrappps

    Joined:
    Feb 12, 2017
    Posts:
    24
  18. LoudCorp-Games

    LoudCorp-Games

    Joined:
    Nov 9, 2016
    Posts:
    2
    most stupid question I have ever seen.