I have references to scripts in Start() function like this
sm = GameObject.FindGameObjectWithTag("SM").GetComponent<ScoreManager>();
cm = GameObject.FindGameObjectWithTag("Camera").GetComponent<Cam>();
even for extra caution I added in Update() to check if it is null and if yes find them again but I have problem that it removes it’s refrence alone and it is null.
I think it forgets them after step it was referenced. After thoese references in start i added call to function to check buttons and it works, any time later if i call it again it just says null reference.
EDIT: also after first use of button.interactable it just says "
MissingReferenceException: The object of type ‘Button’ has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object."
while i clearly checked in inspector that it is active and not deleted and didnt change stored reference (it was drag&drop in inspector public reference)
right after your code in the Start() check if they actually get set.
Do print(sm) and if it prints ‘null’ in the console they’re probably not even set in the first place.
As far as I know references never really get removed unless you use Destroy() to remove the object or if you set it to null manually.
Yeah i know, its so weird, i even put print(sm); in update function and tells scoremanager is referenced but calling function from it returns null reference.
for button it works in other part of script.
it is initalized in start public Button turretbutton;
then drag&drop button in inspectpor and it was working
now i made some new updates to game and when i set interactable = false it does what it should but next time i try to set it to true says i destroyed object while in in-game inspector it is still there as it should be
And in update print it said cm was Cam script and when i press button and call this function it says null reference and then continues saying cm is Cam script which makes no sense.
Now i added
cm = GameObject.FindGameObjectWithTag("Camera").GetComponent<Cam>();
every time i need to use cm and that is workaround but still, why is that problem happening?