- Home /
Object reference not set to an instance of an object
Hello Guys,
So, I'm basically working on a shooting script and I'm getting this errors : NullReferenceException: Object reference not set to an instance of an object. Here's the important lines :
public var shootingScriptGO : Transform;
var shootingScriptGO : Shooting = shootingScriptGO.GetComponent('Shooting');
if(Physics.Linecast(transform.position , shootingScriptGO.hit.point)){
}
Best Regards,
Nbo
add some Debugs and feedback what does these wrote in console
public var shootingScriptGO : Transform;
var shootingScriptGO : Shooting = shootingScriptGO.GetComponent('Shooting');
Debug.Log(shootingScriptGO); Debug.Log(Shooting); Debug.Log(shootingScriptGO.hit); Debug.Log(shootingScriptGO.hit.point);
if(Physics.Linecast(transform.position , shootingScriptGO.hit.point)){
}
Answer by mark24 · Aug 15, 2012 at 04:56 PM
I think it will have something to do with the names you are using. This has happened to me when I capitalized something in the script that wasn't capitalized in the project. You could also try not casting shootingScriptGO, I choose not to since I usually am not changing the script var anyway. Also what exactly is the shootingCriptGO in the project? Here is an example of how I have been doing this.
var guiObj = GameObject.Find("GUIobject"); badgeScript = guiObj.GetComponent("Badges");
I have a GUIobject in the project and a script named Badges.js attached to said object. Hope this helps :)
It's working very well, but now I'm getting other error I think it is due that my script is old and buggy (it was just to learn), so I'm gonna write a more advanced one. Thanks!
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Position of a GameObject 2 Answers
Trouble with raycasting 0 Answers