Object Becoming Null after Click

Here is the related code:

Debug.Log(InventoryManager.Instance.From + "This is my from right now");
        if (InventoryManager.Instance.HoverObject != null)
        {
            Vector2 position;
RectTransformUtility.ScreenPointToLocalPointInRectangle(InventoryManager.Instance.Canvas.transform as RectTransform, Input.mousePosition, null, out position);
            position.Set(position.x, position.y - hoverYOffset);
            InventoryManager.Instance.HoverObject.transform.position = InventoryManager.Instance.Canvas.transform.TransformPoint(position);
        }

        if (Input.GetMouseButtonUp (0))
        {

            Debug.Log(InventoryManager.Instance.From + "This is my from after clicking");
            if (!isMouseOver && InventoryManager.Instance.From != null)...

Somehow that first debug line comes back as SlotType, which is expected behavior after I select an item from the inventory window. Without doing anything else, I click away from the inventory window and suddenly InventoryManager.Instance.From is null!

Worse, this problem sometimes resolves itself after I have been playing for a little while, but not on every run of the game. I am so confused right now what could possibly be happening.

All of this code is inside of my Update function.

Apologies for my code formatting, I’m not sure why that line won’t indent for me.

Scratch that, there was another onclick event in my equipment window that I wasn’t accounting for that was setting my From slot to null.

What type of object is “From”?

Basically one of two things is happening:

  • You are setting InventoryManager.Instance.From = null somewhere else in your code
  • You are Destroy()-ing either the From object or the GameObject it is attached to (or one of its parents).

Are you destroying anything in your code?

Edit: yep

Haha but thank you anyway :slight_smile: