Stuck on MissingReference

So basically I’m working on implementing a inventory and I got the item to destroy and add to my inventory but when if click the item on the inventory it is supposed to (for now) just instantiate back at the players position but I’m getting a MissingReference.
I read a few places to get a instance of the instantiation but I’m not sure where to go from there.

Any ideas?

This controls the inventory buttons and the instantiation

void OnGUI () {
		if (disp) {
			float yOffset = 5;
			
			GUI.Box (new Rect(xOffset, 0, winWidth, winHeight), "");
			
			for (int i = 0; i < invent.Count; i++) {
				if (GUI.Button (new Rect(buttonXOffset, yOffset, buttonWidth, buttonHeight), invent[i].itemName)) {
					Instantiate (invent[i].itemPrefab, player.position, Quaternion.identity);	
				}
				GUI.Box (new Rect(amtXOffset, yOffset, amtWidth, buttonHeight), invent[i].itemQuantity.ToString ());
				yOffset += 5 + buttonHeight; 
			}
		}
	}

this is my BaseItem

using UnityEngine;
using System.Collections;

public class BaseItem : MonoBehaviour {
	
	private InventoryMaster inv;
	private bool lootable = false;
	
	public bool canLoot = true;
	public GameObject itemPrefab;
	public string itemName;
	public string itemDescription;
	public Texture itemIcon;
	public SlotType itemSlot;
	public int itemQuantity;
	public int itemValue;
	public int itemMass;
	public int itemId;
	public int maxStack = 60;
	
	private Transform player;
	private float dist;
	private Transform myTransform;
	
	// Use this for initialization
	void Start () {
		myTransform = transform;
		player = GameObject.FindGameObjectWithTag ("Player").transform;
		inv = GameObject.Find ("GameMaster").GetComponent<InventoryMaster>();
	}
	
	// Update is called once per frame
	void Update () {
		if (canLoot) {
			dist = Vector3.Distance (player.position, myTransform.position);
			if (Input.GetButtonDown ("Interact")) {
				//if (dist < 4.0f) {
					Loot ();
				//}
			}
		}
	}
	
	public void Loot() {
		if (lootable) {
			inv.AddItem (this);
			Destroy (myTransform.gameObject);
		}
	}
	
	void OnMouseEnter() {
		lootable = true;	
	}
	
	void OnMouseExit() {
		lootable = false;
	}
	
	public enum SlotType {
		//Armor
		Head,
		Chest,
		Legs,
		Feet,
		Gloves,
		//Weapons
		Weapon,
		Ammo,
		//Items
		Item
	}
}

this is all I have right now for getting the instantiation

	private void Die() {
		Destroy (this.gameObject);
		lootClone = Instantiate (posLoot[0], transform.position, Quaternion.identity) as GameObject;
		
	}

Any ideas on how to make this work?

not sure but this is certainly due at somthing you destroy then want to reuse a component of the destroyed object

what say the error message exactly ?

in your last 5 line code where you get instance, you destroy current gameObject then after that try using it transform component to perform your instance method…doesn’t seem logic to me, and you should destroy the object only when you finish to deal with it components

well not sure if this si your issue , hope that help :slight_smile:

Lol You ddn’t understood what I mean’t on what I was trying to do.
I’m just trying to instantiate a prefab of the object. In my BaseItem Script that is attached to the object I have a public variable itemPrefab which I assign in the inspector. This prefab variable is copied into my inventory when i pickup the item and then item is destroyed.
Then when i click the item in my inventory it should instantiate it where the player is positioned but it is giving me the above error
Note that it will instantiate the prefab if I use a prefab different than the one of the item
(For example, the item prefab is a cube, if I assign the cube prefab to the variable then I get the error, but If it give it the value of the sphere prefab then everything works perfectly and the sphere is instantiated at the players position.)