Is this a possible bug (very funny bug) in Unity 4.6.1f1?

I am currently still using Unity 4.6.1f1. My game has some requirement to call the Animator.SetTrigger frequently to play a state transition. In fact it helps animate the damage text above the enemy when hit by some bullet. I used Profiler to see what was happening to a fairly serious drop in performance and it’s very funny that there is some internal LogStringToConsole called inside Animator.SetTriggerString (which is inside Animator.SetTrigger).

Looks like they forgot removing that debugging line. I’m not sure if this funny bug was fixed in next versions.

You are probably trying to set a parameter value on a Uninitialized controller, either there is no controller attached to your animator or your controller is disabled?

No, the gameObject (wrapping a Text) does have animator. It has only 1 trigger which I can use SetTrigger in script to animate it. It does animate OK and such as with less than about 20 texts animated simultaneously, there won’t be no noticeable drop in performance. However my game may require more than 100 texts. That’s when it became obvious before I tried using Profiler. As far as I know LogStringToConsole is very expensive and just for debugging purpose.

In fact I was trying to avoid using SetActive to show the animated text. The Animator has only 1 state and will play on awake. Without using SetActive, I have to prepare 2 states, one is idle and one is show. The idle is the default state, a trigger is setup to switch to show state in script. I’ve also tried using SetBool instead but the same the LogStringToConsole is still used. Currently I still use SetActive to show my texts. They are reusable (managed by a pool). The performance is of course not good enough so I had to limit the number of animated texts.

Does anything actually show up in the console?

It’s strange that there is not any thing printed in console window. Also in some frames, there is not any LogStringToConsole inside Animator.SetTriggerString. I think my pool does its job OK. It just checks if there is any in the queue to use. If yes then dequeue it and call SetTrigger. Right after that start a coroutine waiting for a duration of the animation (even plus more some delay) before collecting (enqueueing) it back (and reset) for reusing. If there is not any in queue, just instantiate a new text. When using SetActive, the code does not change much. I just change the SetTrigger to SetActive (and edit the reset method a little). At least using SetActive works and it has fairly much better performance. Using SetTrigger, it works only when there are not many texts running at the same time (not really at same time but in a very small duration). When it works, there is not any LogStringToConsole noticed in the Profiler.

Anyway the LogStringToConsole is of the Animator.SetTriggerString. In some condition it is called and shown up in the Profiler. If it was not called, the performance would be of course better.

do you have warning message ON in your console? last 3 button in top console bar need to be pressed to see message,warning and error

The only reason for LogStringToConsole to be called it because there is a problem, it could be :
Parameter type ‘mytrigger’ does not match.
Parameter 'myTrigger does not exist.
Animator has not been initialized.
Parameter ‘myTrigger’ is controlled by a curve.

2 Likes

Well I turned off the warning messages. Forgot looking into that. It does have a warning saying Animator has not been initialized. However I don’t quite understand why it’s that. All the gameObjects won’t be destroyed (never), they won’t also never be deactivated (SetActive(false)). Each one is instantiated from a template (prefab) and this does have Animator component with a setup controller. So it’s very strange that it can go into uninitialized state. Also that happens only when there are many texts animated. This looks like a serious exception rather than a warning message.

The only possibility I can think of is right after instantiating a new gameObject and getting the animator with GetComponent(), sometimes it won’t be ready to use SetTrigger? Do you know how to ensure (or force) the Animator to initialize? Thanks!

yes you can use

if you still have an warning after calling rebind then it mean that your controller is not in a valid state.
Let me know if it does happen

1 Like

Well I’ve just double-checked it. In fact the Text is not deactivated but its parent (I used a root panel to contain all texts) may be. That’s when the enemy goes out of camera view (but maybe this part does not work correctly). Now it works OK without any warning. Thank you very much for your support.