Shop.cs:68 NullReferenceException ConfirmTransaction

image

it seems the “item” in line 68 does not exist, but line 56 would have stopped this? and the debugs show the item does exist?

public void ConfirmTransaction()

    {          

        Inventory shopperInventory = currentShopper.GetComponent<Inventory>();

        if(shopperInventory = null) return;

        // Transfer to or from the inventory

        var transactionSnapshot = new Dictionary<InventoryItem, int>(transaction);

        foreach (InventoryItem item in transactionSnapshot.Keys)

        {

            Debug.Log(item.name);

            int quantity = transactionSnapshot[item];

            Debug.Log(" qty = " + quantity);

            for (int i = 0; i < quantity; i++)

            {

                bool success = shopperInventory.AddToFirstEmptySlot(item, 1);

                Debug.Log(" found slot = " + success);

                if (success)

                {

                    AddToTransaction(item, -1);

                }

            }

        }

        // Removal from transaction

        // Debting or Crediting of funds

    }

found issue in Shop.cs:56 missing an =, was setting shopperInventory to null :frowning:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms