|
In my scene, I have a prefab of a particle (also tested it with a plain sphere to no avail) that I am trying to instantiate at the collision of a ray (as a bullet explosion). I figured I would get this error if the prefab didnt contain any objects but that is not the case. (The prefab icon is blue) This is just another flaw in my code, I bet, that results from my lack of experience. Thanks in advance for helping! Ive attached this script to the object that is shooting the ray that results in the collision.
(comments are locked)
|
|
From everything you've described so far, it would appear that the particular instance you're examining is set up entirely correctly. Which leads me to think, could it be that you've accidentally dropped that script onto some other GameObject in your hierarchy too, without realising? If so, it may be that instance which is throwing the error (as opposed to the one you're inspecting, which seems fine).
(comments are locked)
|
|
Thanks so much for your answers! My problem is solved. The problem was actually that I was dragging the Bulletspark prefab into the script and not the instance of the script in the object that fires the raycast. I predicted that this was a problem related to a misunderstanding in the interface. Once again thanks for your answers. This community is awesome.
(comments are locked)
|
|
This is checking the obvious, but, you're sure that bulletspark is correctly pointing to the Prefab, in the Editor window? You did a drag/drop, or used the dropdown menu, and it's connected to the public script variable? I've had times when I accidently disconnected a variable without noticing. Yes, I have made sure of this..
Mar 16 '10 at 07:54 PM
Expendis
Yes, the picture shows bulletspark as connected - but gun is null. I don't see it in the script above, is it also instantiated, and could the error message be from that code instead?
Mar 16 '10 at 08:20 PM
Cyclops
Hm, yes you're not trying to instantiate the gun, but you are using it to fill the variable "gunPosition". If 'gun' isn't assigned, you should get a null reference error though, not a Prefab is null error. Strange.
Mar 16 '10 at 08:51 PM
duck ♦♦
(comments are locked)
|
|
Have you changed the type of the variable 'bulletspark' since you made the drag-reference? For example, perhaps it used to be:
...or something else, when you made the drag-reference, and then maybe you changed the type to:
If so, you have to re-drag the reference even though it appears to still be linked. I can't remember off the top of my head whether this generates the error that you describe, or a different error, but it's one more thing to check. If you can't remember whether you changed it, just try re-dragging the reference anyway and see if it fixes it. If it does, that was most likely the cause of the problem. I havent changed the variable type but to be sure, I dragged it in again and Im still getting the same error. Thanks for your help so far!
Mar 16 '10 at 08:14 PM
Expendis
@Duck, that's a good point - why is it a Transform, anyway? A Prefab is really a GameObject. If you didn't change it, @Expendis, might try it.
Mar 16 '10 at 08:22 PM
Cyclops
I changed it to a GameObject, and to make sure that the glitch you mentioned wasnt occurring, @Duck, I dragged the prefab back onto Bulletsparks on the script. ...To no avail. Same error, same place in the script. I greatly appreciate your help in this! Thanks everyone.
Mar 16 '10 at 08:43 PM
Expendis
It should work as a transform, if you didn't change it after the drag. You can instantiate a prefab from a reference to any type of component attached to it. Whichever you use, the entire prefab will be instantiated in its complete form.
Mar 16 '10 at 08:44 PM
duck ♦♦
(comments are locked)
|

