Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Duplicated Animations between prefabs

Tags:

c#

unity3d

I got two and more instances of the same prefab in a scene. Every one of them has an animator, and every one of them has the same animator controller connected to it. When I animate one of them, all of them get the very same animation. Any clues on what on earth is there happening? Should I have a separate animator controller for every player on scene? How do I separate animators from each other in C#?

like image 572
Duobix Avatar asked Nov 01 '22 08:11

Duobix


1 Answers

I will add this as an answer even though you didn't put your code as a resources. This is just going to be my Bet.

I have made a game that also shares animator with the same prefabs but if you are calling just the GameObject that needs to animate. It should not call the other Animator calls An Object is Instantiated with different Animators each time, even if the file of the Animator is the same.

To Test this I would suggest that each time you instantiate your GameObject. name it something else. for example.

public GameObject[] myPrefabs; //make sure to add the size in the inspector

myPrefabs[0] = (GameObject)Instantiate(nameofPrefab);
myPrefabs[0].name = "myPrefabs0"; // this is to make sure that name (Clone) is removed;

// Then call the animation.
myPrefabs[0].GetComponent<Animator>().SetTrigger("Attack");

//SetTrigger, SetBool, SetInt. Since it is an Animator

I use List instead of Array, but I think this is the most basic one that I can give.

The naming of the prefab is not necessary to fix your problem. But you need it so you can check if it is the correct GameObject that is taking your Animator Call

like image 83
Aizen Avatar answered Nov 15 '22 06:11

Aizen