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

UnassignedReferenceException: The variable selectionPrefab of ‘rayCast’ has not been assigned.
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.

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.