Search Unity

Question Colliding gameObject stored in a variable turning null for no apparent reason (Fixed)

Discussion in 'Scripting' started by sobsurfing, Jan 7, 2022.

  1. sobsurfing

    sobsurfing

    Joined:
    Mar 3, 2017
    Posts:
    14
    Hey! So I'm using a collider and store the colliding game object in a variable, which works and is never set back to null. But when I try to access it from the OnMouseUp Unity method it's always shown as null, same thing if I put it in a list: the list length will be 'magically' zero even though the events happend in the right order and the var is still not null..



    I did a second test making sure I would never assign a null value, as you can see with the replaced line down below. And I printed the variable content on Update(). As you can see it alternates for some reason.



    Any ideas? Thanks!

    Edit: Turns out the issue was outside the code!
     
    Last edited: Jan 7, 2022