Controller Help

How do I trigger another game object’s animation/animator?
This is the reference for the other object that I want to trigger. The script below is attached to the main object, and should trigger the other object’s animation. But I keep getting console log message (Animator is not playing an AnimatorController)

public class TriggerScript : MonoBehaviour {
public GameObject otherObject;
Animator anim;

private void Start()
{
anim = otherObject.GetComponent();
}

private void OnMouseDown()
{
anim.SetTrigger(“Active”);
}
}

“Active”, is the name/string of the trigger from the animator of the other game object. On the inspector tab in unity, I drag and drop the other game object in the public variable. Please help

Is the Animator active and enabled at the time of execution?

More specifically, are you calling this on a prefab instead of a GameObject in the scene?

Based on the error message it’s almost certainly this.

if you have dragged the prefab into this slot you need to first Instantiate() that prefab and keep a reference to the GameObject returned from Instantiate and use that for your otherObject

In other news, I highly recommend using meaningful names, such as:

[Header( "Fill this in with the player prefab")]
public GameObject PlayerPrefab;

// assign the Instantiate-d player to this and only use this for everything at runtime
private GameObject InstantiatedPlayer;

Always seek to reduce confusion. If you use the word Object you are asking for confusion.

Thank you for the reply. Yes it is a prefab.

You can’t do operations like this on Prefabs, it needs to be instantiated first.

Thankyou for the reply. Forgive my errors, I will take that on board.

Instantiate first, then call the animation. Thankyou again.

Make sure to call the animation on the newly Instantiated object :wink: