Ok, I’m working on an inventory system, and I’ve got the character to pick up the item, but putting it down just in front of the player is not working so well.
Here is the error:
ArgumentException: The thing you want to instantiate is null.
UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:102)
UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at C:/buildslave/unity/build/Runtime/Export/UnityEngineObject.cs:79)
Inventory.DropFromHands () (at Assets/Scripts/Inventory.cs:154)
Interactions.Update () (at Assets/Scripts/Interactions.cs:46)
Here is the code that has the error:
public void DropFromHands ()
{
Debug.Log ("DropFromHands called!");
if (inventorySlots[5] != "0") {
int c;
GameObject oldItem = GameObject.Find(inventorySlots[5]); Debug.Log (oldItem);
for (c=0;c<items.Length;c++)
{
if (items
== oldItem.transform)
{
dropping = items[c];
Debug.Log (items[c] + " was found and added.");
}
else
{
if (c == items.Length)
{
Debug.LogError ("Finished searching through the list, nothing was found!");
}
if (c != items.Length)
{
Debug.Log ("Checked Item " + c + "/" + items[c] + " against " + oldItem.transform + ", moving on!");
}
}
}
GameObject inHands = GameObject.Find(inventorySlots[5] + "_hand");
inHands.layer = 8;
Debug.Log ("Item to be destroyed: " + dropping);
Instantiate (dropping, new Vector3(player.position.x,player.position.y,player.position.z), oldItem.transform.rotation); Debug.Log("Placed item on ground!");
}
}
As you can see I've got a lot of debugging loggers attached so here is the list of logs in order:
DropFromHands called!
UnityEngine.Debug:Log(Object)
Inventory:DropFromHands() (at Assets/Scripts/Inventory.cs:127)
Interactions:Update() (at Assets/Scripts/Interactions.cs:46)
Traffic Barrel (UnityEngine.GameObject)
UnityEngine.Debug:Log(Object)
Inventory:DropFromHands() (at Assets/Scripts/Inventory.cs:130)
Interactions:Update() (at Assets/Scripts/Interactions.cs:46)
Checked Item 0/Traffic Barrel (UnityEngine.Transform) against Traffic Barrel (UnityEngine.Transform), moving on!
UnityEngine.Debug:Log(Object)
Inventory:DropFromHands() (at Assets/Scripts/Inventory.cs:146)
Interactions:Update() (at Assets/Scripts/Interactions.cs:46)
Item to be destroyed:
UnityEngine.Debug:Log(Object)
Inventory:DropFromHands() (at Assets/Scripts/Inventory.cs:153)
Interactions:Update() (at Assets/Scripts/Interactions.cs:46)