This warning also occurs, when you try to run methods on an Animator (SetFloat/Play/etc.) that is attached to a Prefab, instead of a instantiated GameObject.
For example:
You have a GameObject (name - “MyLists”) with List type Duck.
Duck is just a regular prefab with a script that has a method , let’s say… “ShowUp()” .
The list fullfills with Duck GameObjects by itself. Doesn’t matter how.
Your other GameObject (name - “Manager”) on a scene runs method “ShowUp()” on every Duck GameObject in the list. But because of some reason, you want to run method “ShowUp()” even if there are no object (no Ducks) on the list. Because this method makes some cool stuffs. So you assign the Duck Prefab to the Manager GameObject, so it can take a script from this Duck prefab, and run method “ShowUp()”.
If the method “ShowUp()” has something like “animator.SetFloat(…)”, it will cause an warning we’re talking about.
*It will not cause an error “animator not assigned”, because Duck prefab may have assigned “animator” in the Inspector.
Next part of this post is about a real “Duck” problem that I’ve had
You don’t need to read it if you’re not interested, you already know everything that you need about error/warning we’re talking about.
You can say… Well, that’s weird thing won’t ever happen, why should I run “ShowUp()” when there are no Ducks. But that’s not true. Look at this:
I make a multiplayer game with object pooling. Only the Master Client (or server) can add new objects to the pool. After that he send message to everyone that he has just created a new object in the pool, and everyone needs to that in theirs local pools too (to stay synchronized).
Of course, all this time the Master Client sends data about every object in the pool to other players, so they can be synchronized (like position, velocity, etc.). Every data he sends MUST be read by a client. If that won’t happen client may read “old” data as a new message, and assing values (like position, velocity) to a different object in the pool.
In case Master Client adds new object to the pool, he starts to send data about it to everyone. Sometimes client won’t catch up to make this new object before he gets informations about it. So he need to make something like “fake read”, just read informations but do not assign them to any gameobject (because he didn’t create the proper one). That is when I want to use Read method from a prefab, I just set a parameter fakeRead to True in method Read(bool fakeRead) and it does a fake read. If in my Read method I use animator.SetFloat((float) stream.ReceiveNext()) it will cause an warning we’re talking about, because an animator is a prefab’s animator.
Let’s say the Master Client has just created third object, and he now sends informations about objects.
for every object:
object.SendsInfo()
(it will runs 3x times)
Client didn’t create object3 yet, but he receives data:
for every object:
object.Update(stream.ReceiveNextData())
(it will runs 2x times)
in next loop Client will subscrive informations about object3 to object1 !!!
Of course I propably can walk around this problem in a different way, maybe like flushing streams, change the way master communicates with client, etc. But hey! that’s my solution for now and it works perfect!