- Home /
Reference disappearing from inspector on Play
In my game I'm designing, I have my enemy controls referencing my score, which is a separate script attached to a separate object. I have the object reference set int the inspector and even in the prefabs, but when I attempt to play my scene, the reference shows "None." How can I alleviate this issue that I'm currently having? The code that I'm using to reference the separate script is in the update function of enemy controls. Also, I've attached some screenshots of the issue. Hopefully someone is able to help me out. The biggest issue is that this was NOT happening last night while I was working on it and suddenly, poof, my reference starts disappearing. Any help is much appreciated!
playerScore = gameObject.GetComponent("Main_Score");
Before Playing Scene
After playing Scene
I have to bump this because it's already getting lost in the Unity Question abyss. I desperately need assistance on this. If anyone could please help, that would be amazing.
i'm not sure if i understood and i'm just guessing here without your scripts. Shouldn't it be
playerScore = gameObject.GetComponent("$$anonymous$$ain_Score").Player_Score
or something similar? And, if "$$anonymous$$ain_Score" is in another object, you should be calling it by anotherObject.GetComponent
Answer by jaydeepmodha1 · Jun 05, 2019 at 06:16 AM
Try not "GetComponent" instad try "FindObjectofType" maybe this may work for you.@SlyyGuyy.
Your answer
![](https://koobas.hobune.stream/wayback/20220613142938im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Folder Trick Doesn't Work: Referencing JS from C# 0 Answers
Getting a reference to a class created in a different gameObject (Javascript) 1 Answer
How does one declare a public variable without exposing it (in Javascript)? 0 Answers
Need health to decrease with movement in Javascript 1 Answer
Your "own" structs ... are they indeed passed by value? 1 Answer