-
-
Notifications
You must be signed in to change notification settings - Fork 97
Description
On a domain reload, RCSG reinitializes and creates an extra hidden [default-CSGModel]
gameobject even when one is in the scene. It creates the object in the active scene rather than the scene with the model.
The immediate cause is in InternalCSGModelManager.DefaultModel.cs
at line 111 where sceneState.DefaultModelObject
is set to a new gameobject. There appears to be no way in Unity to instantiate a gameobject in a particular scene unless creating a prefab for some reason.
Adding SceneManager.MoveGameObjectToScene(sceneState.DefaultModelObject, currentScene);
to the following line appears to move the gameobject successfully, but at the end of the domain reload it shows up in the hierarchy in the wrong place. I can't tell if it's being moved by some RCSG methods later in initialization, or some arcane Unity nonsense.
On the next domain reload / initialization, the default model is searched for with SceneQueryUtility.GetUniqueHiddenGameObjectInSceneWithName
, but that correctly searches the added scene and therefore doesn't find it, so it creates another one. If the scene is opened alone, or is set active during a reload, the hidden models are removed by that method.
It appears that objects marked DontSave
hang around through scene changes (additive or not) in the editor hierarchy if something has a reference to them. That may be part of the issue, but I have not 100% confirmed this.
From the docs: "The object will not be saved to the Scene. It will not be destroyed when a new Scene is loaded. You must manually clear the object from memory using DestroyImmediate to avoid memory leaks."
A constant issue with rcsg in my experience is giant git diffs or git diffs for scenes with no changes, even when not saving meshes in scene files. Often the problem appears to be objects just shuffling their order in the hierarchy. Since Unity instantiates things in weird places in the hierarchy sometimes, this may be (one of) the causes of that issue as well.