- Home /
Object.operator bool evaluates oddly
In the scripting manual it specifies that if(rigidbody)
is the same as if(rigidbody!=null)
. Yet I'm getting different behaviour depending on which syntax I use (in UnityScript). When I use the latter my game proceeds as normal, but when I stop play in the Unity Editor, I get the errors:
!IsDestroying() UnityEngine.GameObject:set_active(Boolean)
!gameObject.IsActive() Assert in file: /Applications/.../Misc/GameObjectUtility.cpp at line: 773
However when I use the former syntax the error disappears. Am I misunderstanding the syntax of these two commands? My script looks like:
#pragma strict
static function SetActive( inDict : Dictionary.<String,GameObject>, newState : boolean )
{
for(var cObj in inDict.Values)
if(cObj!=null)
(cObj as GameObject).active = newState;
}
Answer by Waz · May 06, 2011 at 09:50 AM
if (rigidbody)
that uses the cast-to-bool operator, which in Unity will also check if the Component is being Destroy()ed. The documentation is just glossing over the details. Somehow your elements of inDict are being destroyed. Probably if elsewhere you used DestroyImmediate, you'd get different behaviour again.