The object of type 'Script Name' has been destroyed but you are still trying to access it.
I have a mechanic in my game that when the player stands on the floor, the floor changes color depending on how long you stand on it. The script that does this is called FloorIndicator and is attached to a plane with a collider set as a trigger.
The goal of the game is to steal valuables from the enemy's home without getting caught. The collider triggers on the planes with FloorIndicator attached are not enabled until the enemy has spawned, or "returned home"
When I load the game initially it all works fine. When you reach a goal for the level you can exit the level. After a screen showing your score, you are then loaded back into the first level I mentioned. It is at this point of reloading the level that my problem occurs.
When the enemy spawns and the floor triggers should be enabled, this error appears:
MissingReferenceException: The object of type 'FloorIndicator' 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. UnityEngine.Component.GetComponent[T] () (at C:/buildslave/unity/build/Runtime/Export/Scripting/Component.bindings.cs:42) FloorIndicator.ActivateFloor () (at Assets/Scripts/Game/FloorIndicator.cs:87) GMManger.EnemySpawnAlert () (at Assets/Scripts/Game/GMManger.cs:26) GMManger.Update () (at Assets/Scripts/Game/GMManger.cs:50)
I don't destroy any object in the scene that should make the planes with the FloorIndicator be destroyed.
Here are the relevant script snippits:
On the FloorIndicator script
void ActivateFloor()
{
if (this.GetComponent<Collider>().enabled == false)
this.GetComponent<Collider>().enabled = true;
}
The script itself is an observer subscribed to a game manger script that notifies when the enemy has spawned.
This is the part of the game manger script than notifies when the enemy has spawned
void Update()
{
if(countDown > 0 && countingDown == true)
countDown -= Time.deltaTime;
else
{
countingDown = false;
SpawnEnemy();
EnemySpawnAlert();
}
if (valueScore >= goal)
exitTrigger.enabled = true;
}
Sorry If this wasn't clear. Really need help with it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612232158im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Order of SceneManager.LoadSceneAsync and UnloadSceneAsync. 0 Answers
Load all scenes in splash screen 0 Answers
Printing total time to open/loading a scene 0 Answers
Destroy object with dontdestroyonload 2 Answers