|
I'm having problems with this working: ObjectA has ScriptA attached to it ScriptA
ScriptB
When I call makeRefObjDoSomething(), Unity says "Object reference not set to an instance of an object", I thought this was a legal call?
(comments are locked)
|
|
The error means that refObject is not set to anything. That means that either ScriptB.Start() was not called yet (e.g. if the object containing ScriptB was just Instantiated this frame), or, when it was called it did not find the object/script in question. I'd pepper in some Debug messages (e.g. a Debug.Log("ScriptB.Start()");), and separate the GameObject.Find and GetComponent calls (in case the Find returns null. I'd also use the Type, rather than the string version of GetComponent, i.e. GetComponent(typeof(ScriptA)), or the generic version. What I ended up doing was changing the Start() to Awake(), kinda cheap trick, but I gots deadlines approaching fast. Thanks for your help.
Oct 29 '10 at 01:20 AM
LifeSizeDeity
(comments are locked)
|
|
Try debugging refObject.gameObject.name immediately after you do the find command to make sure it's getting the component properly. If it's not finding the object properly, tweak the way you're looking for it by either using FindWithTag. If it is finding the object properly, go into debug mode in the editor to make sure something else isn't clearing the reference for some crazy reason, or that objectA isn't getting destroyed.
(comments are locked)
|
