Hey. So I have managed to shoot a light from a wand in my game, it works okayish for now, however in the console I keep getting this error:
UnassignedReferenceException: The variable projectile of 'Light_Spell' has not been assigned.
You probably need to assign the projectile variable of the Light_Spell script in the inspector.
UnityEngine.Object.Internal_InstantiateSingle (UnityEngine.Object data, Vector3 pos, Quaternion rot)
And the line of code the error points to is this:
Rigidbody instantiateProjectile = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
How can I solve this? Its probably some dumb error but I’m new to Unity so not sure what it could be.
1 Like
You should not approach errors like they are dumb, unless you are %100 sure that you know the cause and it is really dumb. All errors must be fixed in sight :).
When I had the same error, the reason was that I had accidentally dragged the script to a wrong object in the scene view, after which I had attached the script to the correct object. Sounds like a joke, but nontheless, check if your script is attached to any unwanted object.
had the same prob. but yes, mistakenly assigned the script to the wrong object. thanks it worked. +1
This was it for me. Except it wasn't an accident, I just thought that unchecking the script on the other object would mean that it no longer affects anything. Apparently not.
Did you assign the variable to the script its self or the object that the script is on?
If you assigned it to the script assign it to the object the script is on instead.
I have a WandLight that has the LightSpell script attached to it and that has the Light_Shot prefab put into it. I just dragged and dropped the prefab onto it
You should not approach errors like they are dumb, unless you are %100 sure that you know the cause and it is really dumb. All errors must be fixed in sight :).
– FeyyyyyThis error causes because projectile property of Light_Spell script is null. How do you assigning projectile property of Light_Spell?
– Feyyyyy