I’m trying to change a variable within an object.
Initially, I was planning to just get the variables from the object in advance and pass them down, but since I needed a reference to save them, I switched to passing the object and getting the variables from it.
However, despite doing the exact same thing, the latter will cause a reference error and the function will stop working.
What is the difference between pre-getting variables from an object and passing an object and getting variables from it?
When you are passing an object you are passing it it’s address in memory and using that to access the object. If the object becomes invalidated via garbage collection then the address will become invalid and you cant access it’s data. (it will point to null)
When you pass in pure variables then you are directly passing the specific variable, so an int of value 5 or a bool that is false. The variables cannot be invalidated along the way.
1 Like
In other words, for stability, it is better to pass the variables directly.
Thank you for the clear explanation.
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.