Skip to content

Commit

Permalink
Renamed SceneContext property parentNewObjectsUnderRoot to parentNewO…
Browse files Browse the repository at this point in the history
…bjectsUnderSceneContext
  • Loading branch information
svermeulen committed Oct 20, 2018
1 parent 7eed952 commit a0ad097
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2508,7 +2508,7 @@ If you add bindings for classes that implement `IDisposable`, then you can contr

Unity has a concept of "script execution order" however this value does not affect the order that OnDestroy is executed. The root-level game objects might be destroyed in any order and this includes the SceneContext as well.

One way to make this more predictable is to place everything underneath SceneContext. For cases where a deterministic destruction order is needed this can be very helpful, because it will at least guarantee that the bound IDisposables get disposed of first before any of the game objects in the scene. You can also toggle the setting on SceneContext "Parent New Objects Under Root" to automatically parent all dynamically instantiated objects under SceneContext as well.
One way to make this more predictable is to place everything underneath SceneContext. For cases where a deterministic destruction order is needed this can be very helpful, because it will at least guarantee that the bound IDisposables get disposed of first before any of the game objects in the scene. You can also toggle the setting on SceneContext "Parent New Objects Under Scene Context" to automatically parent all dynamically instantiated objects under SceneContext as well.

Another issue that can sometimes arise in terms of destruction order is the order that the scenes are unloaded in and also the order that the DontDestroyOnLoad objects (including ProjectContext) are unloaded in.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ public class SceneContextEditor : RunnableContextEditor
{
SerializedProperty _contractNameProperty;
SerializedProperty _parentNamesProperty;
SerializedProperty _parentNewObjectsUnderRootProperty;
SerializedProperty _parentNewObjectsUnderSceneContextProperty;

public override void OnEnable()
{
base.OnEnable();

_contractNameProperty = serializedObject.FindProperty("_contractNames");
_parentNamesProperty = serializedObject.FindProperty("_parentContractNames");
_parentNewObjectsUnderRootProperty = serializedObject.FindProperty("_parentNewObjectsUnderRoot");
_parentNewObjectsUnderSceneContextProperty = serializedObject.FindProperty("_parentNewObjectsUnderSceneContext");
}

protected override void OnGui()
Expand All @@ -28,7 +28,7 @@ protected override void OnGui()

EditorGUILayout.PropertyField(_contractNameProperty, true);
EditorGUILayout.PropertyField(_parentNamesProperty, true);
EditorGUILayout.PropertyField(_parentNewObjectsUnderRootProperty);
EditorGUILayout.PropertyField(_parentNewObjectsUnderSceneContextProperty);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ public class SceneContext : RunnableContext
public static IEnumerable<DiContainer> ParentContainers;

[FormerlySerializedAs("ParentNewObjectsUnderRoot")]
[FormerlySerializedAs("_parentNewObjectsUnderRoot")]
[Tooltip("When true, objects that are created at runtime will be parented to the SceneContext")]
[SerializeField]
bool _parentNewObjectsUnderRoot;
bool _parentNewObjectsUnderSceneContext;

[Tooltip("Optional contract names for this SceneContext, allowing contexts in subsequently loaded scenes to depend on it and be parented to it, and also for previously loaded decorators to be included")]
[SerializeField]
Expand Down Expand Up @@ -94,10 +95,10 @@ public IEnumerable<string> ParentContractNames
}
}

public bool ParentNewObjectsUnderRoot
public bool ParentNewObjectsUnderSceneContext
{
get { return _parentNewObjectsUnderRoot; }
set { _parentNewObjectsUnderRoot = value; }
get { return _parentNewObjectsUnderSceneContext; }
set { _parentNewObjectsUnderSceneContext = value; }
}

public void Awake()
Expand Down Expand Up @@ -230,7 +231,7 @@ public void Install()
Assert.That(_decoratorContexts.IsEmpty());
_decoratorContexts.AddRange(LookupDecoratorContexts());

if (_parentNewObjectsUnderRoot)
if (_parentNewObjectsUnderSceneContext)
{
_container.DefaultParent = transform;
}
Expand Down

0 comments on commit a0ad097

Please sign in to comment.