in scene loaded additively, static objects are no longer static (?!?)

I’ve got a bunch of scene content I’m loading at runtime with SceneManager.LoadSceneAsync(sceneName, LoadSceneMode.Additive). This is all scenery, so most of it is marked Static (Everything) in the inspector.

At runtime, I want to know whether an object is static or not, so I check gameObject.isStatic. When testing in the editor, this reports true on the objects I would expect. But at runtime (testing on Oculus Quest, if that matters), it returns false on objects that I know should be static.

What’s going on? Is it impossible for statically-loaded objects to actually be static? Does isStatic simply not work in builds? Is it a Unity bug?

Thanks,

  • Joe

Never thought of this question before! But based on this, AND based on its name “Editor Flags”,

I see this blurb:

“Setting StaticEditorFlags at runtime has no effect on these systems.”

Now that’s obvious, but in your case you are reading it… which I imagine is probably just returning false because you’re not in the editor.

Here’s a thought: make your own Monobehavior that by its mere presence on a GameObject indicates that it was static.

Now normally that would be a colossal pain to keep “in sync” with the actual static flags, but check this thread here:

You could make a scene processor that automatically adds your MB to GameObjects that are marked static.

Your MB doesn’t even have to have anything in it except a single static method:

public static bool CheckStatic(GameObject go)
{
  return go.GetComponent<JoeStroutsStaticMarkerBehavior>() != null;
}

And use that in your codez.

Those are reasonable ideas. But my issue isn’t so much detecting whether objects are in a particular category — I realized another, more direct way to tell that.

My bigger concern at this point is whether these objects are or are not static, performance-wise. As our scene grows, it’s going to be very important that these objects batch for rendering, have efficient mesh collider tests, etc. So the fact that they’re reporting nonstatic worries me.

That’s easy: pick one piece of geometry and put a script on it that wiggles it at runtime. If you don’t see it move in the build, it’s static.

2 Likes