[Update: See comment, renamed question for more accuracy]
Hello everybody
I have a confusing problem, probably a bug.
I’ve a script, that manages level of details. There is one script that manages the different lod-objects. When I deactivate this script, I want all lod levels to be visible. This script should also work in edit mode and has the [ExecuteInEditMode] attached.
I set the meshrenderer with the aid of a subroutine:
private void SetMeshRenderer (GameObject obj, bool newState)
{
if (obj.renderer != null)
{
obj.renderer.enabled = newState;
}
for (var i = 0; i < obj.transform.childCount; i++)
{
SetMeshRenderer(obj.transform.GetChild(i).gameObject, newState);
}
}
When I call this subroutine from the method “OnEnable()”, everything works fine, the meshrenderers of the lod levels are updated correctly. But when I use this very same subroutine in the method “OnDisable()”, then I get sometimes a bug.
When the script was deactivated from an object in the 3D scene (GameObject), everything works fine. But when the script was deactivated from the prefab in the library, then the meshrenderers are getting activated (checked with debuging…), but on the prefab and on the instances in the scene, nothing changes…
It’s somehow difficult to describe, because I do not actually understand the problem myself…
Here’s the code I use for the two methods:
void OnEnable ()
{
// Works fine here
foreach (var level in LodLevels)
{
if (level.LodObject== null)
{
continue;
}
SetMeshRenderer(level.LodObject, true);
}
}
void OnDisable()
{
foreach (var level in LodLevels)
{
if (level.LodObject== null)
{
continue;
}
SetMeshRenderer(level.LodObject, true);
}
}
Hope somebody is able to reproduce the error. If not, then I’m going to write an error report…
Greetings
Chillersanim