- Home /
instantiate problem with assigned variable
var selectionPrefab : GameObject;
var currentSelection : GameObject = Instantiate(selectionPrefab);
What I'm trying to do is that I've got a particle effect (emitter/animation/renderer) tied to a prefab that I want to instantiate.
The problem I'm having is regarding this error
You probably need to assign the selectionPrefab variable of the rayCast script in the inspector. UnityEngine.Object.Instantiate (UnityEngine.Object original) (at C:/BuildAgent/work/842f9557127e852/Runtime/ExportGenerated/Editor/UnityEngineObject.cs:56) rayCast.objectSelection () (at Assets/Scripts/rayCast.js:50) rayCast.Update () (at Assets/Scripts/rayCast.js:18) And the problem is really that it makes no sense. I've assigned it using the selection window. Tried dragging/dropping it into the variable slot and I've even tried declaring it in script (which didn't work very well). The script that's run isn't assigned to any object but is rather used for picking and movement. I don't know if that makes a difference or not. These few lines of code are driving me crazy, so any help would absolutely be appreciated.UnassignedReferenceException: The variable selectionPrefab of 'rayCast' has not been assigned.
Answer by aldonaletto · Nov 05, 2011 at 12:47 AM
You may have a lost instance of this script attached to something, and this instance is producing the error. You can add to Start() a debugging line like this:
print("I'm attached to "+transform.name);
You will see this message in the console for each instance of this script, and if there are more than one message, bingo! you found the culprit.
Thanks, that was kinda silly of me, I was assigning the variable directly to the script, not to the camera that it's attached to ^.^'
What a clever answer!! It worked out with my problem too!! If I could I would vote your answer but apparently I don't have enough reputation :( Thanks!
Your answer
Follow this Question
Related Questions
How to Add Y Axis Offset to transform.localPosition on an Instantiated Prefab? 2 Answers
Instantiating one prefab with different materials in one frame 0 Answers
how to destroy camera instatiated from prefab? 0 Answers
Executing code on prefabs that are never instaciated + data loss 0 Answers
Enemy not spawning correctly 1 Answer