- Home /
im getting this error: NullReferenceException: Object reference not set to an instance of an object Item.Start () (at Assets/Scripts/Inventory System/Item.js:9)
i have been looking for a solution for 2 hours now, i hope some of you guys can help me.
the error message: NullReferenceException: Object reference not set to an instance of an object Item.Start () (at Assets/Scripts/Inventory System/Item.js:9)
here's my script: #pragma strict
var objectName : String;
var amount = 1;
function Start () {
objectName = gameObject.name;
transform.Find("Player").GetComponent(InventoryMemory).InvUpdate(objectName, amount);
}
function Update () {
}
I didn't know you could do GetComponent()
ins$$anonymous$$d of GetComponent<>()
but apparently in Javascript you can't always access a C# script using () thats interesting.
Answer by allenallenallen · Jan 02, 2016 at 08:56 AM
transform.Find("Player") will try to find the child GameObject named "Player"
API: http://docs.unity3d.com/ScriptReference/Transform.Find.html
Perhaps the GameObject Player isn't a child object but another GameObject elsewhere?
In that case, you should use GameObject.Find("Player") http://docs.unity3d.com/ScriptReference/GameObject.Find.html?from=index