Animate Object when its Animator is in different Gameobject

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

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

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 ?

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:

3008129--224378--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: Learn game development w/ Unity | Courses & tutorials in game design, VR, AR, & Real-time 3D | Unity Learn
Aside from that there is a lot to said for just experimenting.

Cheers,

TrickyHandz

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.

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

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

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

OK… There is no problem…I think that approach is fast…but not a problem
Will send you project package
Thanks !

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

1 Like

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 !

1 Like

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!

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
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

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:

using System.Collections;
using UnityEngine;

public ObjectSpawner : MonoBehaviour 
{
    [SerializeField]
    private GameObject particlePrefab;
    [SerializeField]
    private GameObject objectPrefab;
    [SerializeField]
    private float waitTime = 2f;

    private void Update()
    {
        // Replace this input code with the
        // action that will trigger the spawning
        if(Input.GetKeyUp(KeyCode.Space))
        {
            StartCoroutine(ShowObjects);
        }
    }

    private IEnumerator void ShowObjects()
    {
        // Instantiate the particles
        Instantiate(particlePrefab);
        // Wait for the amount of time set in
        // the waitTime field
        yield return new WaitForSeconds(waitTime);
        // Spawn the object prefab and
        // Destroy the particle system
        Instantiate(objectPrefab);
        Destroy(particles);
    }
}

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

Thanks for reply…Today I have not checked … But will give it a try tomorrow…
Thanks !

@TrickyHandz

Hi again !
please see http://answers.unity3d.com/questions/1356046/how-to-make-my-3d-gameobject-invisible-if-no-rende.html

@TrickyHandz

I think my question is not published yet … see it here
http://stackoverflow.com/questions/44093738/how-to-make-my-3d-gameobject-invisible-if-no-renderer-attached-in-unity

most stupid question I have ever seen.