I have some code that dynamically adds a component to all objects in a specific layer, which is run at Start and runs fine… until I “restart” the scene using;
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
Rerunning the following code after that still finds the appropriate GameObjects, but never adds the component to them.
void SetWater()
{
GameObject[] waterObjects;
waterObjects = FindInActiveObjectsByLayer(LayerMask.NameToLayer("Water"));
foreach (GameObject g in waterObjects)
{
g.AddComponent<ArcaneWater>();
}
}
Debugging g shows what it should, even after the restart, but for some reason it never adds the component.
I was wondering if this was a known issue or whether I’m doing something wrong.
Anyone know what’s going on?