Search Unity

PhysicsScene is empty after calling MarkSceneDirty

Discussion in 'Prefabs' started by ratking, Jan 5, 2021.

  1. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    350
    Hallo,

    I use Unity 2019.4.17f1. I call the following code when I edit a prefab in the prefab scene:
    Code (CSharp):
    1.  
    2.                 EditorSceneManager.MarkSceneDirty(MyLevel.Current.gameObject.scene);
    3.            
    4.                 var prefStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage();
    5.                 if (prefStage != null) {
    6.                     var scene = MyLevel.Current.gameObject.scene.GetPhysicsScene();
    7.                     Debug.Log("Is empty " + scene.IsEmpty() + " is valid " + scene.IsValid());
    8.                     EditorApplication.delayCall += () => {
    9.                         Debug.Log("Is empty " + scene.IsEmpty() + " is valid " + scene.IsValid());
    10.                     };
    11.                 }
    The first Debug.Log prints False for scene.IsEmpty(), the second True - which means I can't use PhysicsScene.Raycast anymore (even though all the colliders that were there before still exist). Is this expected behaviour? If not, is there a workaround?

    Kind regards,
    ratking
     
    Last edited: Jan 5, 2021
  2. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    350
    Is there really no solution to this? EditorSceneManager.MarkSceneDirty(prefabStage.scene); invalidates Physics, and the only workaround I found so far (calling AssetDatabase.SaveAssets() directly afterwards) creates a lot of other problems.
     
  3. SteenLund

    SteenLund

    Unity Technologies

    Joined:
    Jan 20, 2011
    Posts:
    639
    Well, not really sure.

    How is
    prefStage
    related
    Mylevel.Current.gameObject.scene
    ? Those two might not be related at all, so I am not really sure what you are trying to do
     
  4. ratking

    ratking

    Joined:
    Feb 24, 2010
    Posts:
    350
    Yes, sorry, the gameObject in question is inside the prefStage. They are very much related. It basically is the root gameObject of the Prefab Scene.