Skip to content

Commit a0ad097

Browse files
committed
Renamed SceneContext property parentNewObjectsUnderRoot to parentNewObjectsUnderSceneContext
1 parent 7eed952 commit a0ad097

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2508,7 +2508,7 @@ If you add bindings for classes that implement `IDisposable`, then you can contr
25082508

25092509
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.
25102510

2511-
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.
2511+
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.
25122512

25132513
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.
25142514

UnityProject/Assets/Plugins/Zenject/Source/Editor/Editors/SceneContextEditor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ public class SceneContextEditor : RunnableContextEditor
1111
{
1212
SerializedProperty _contractNameProperty;
1313
SerializedProperty _parentNamesProperty;
14-
SerializedProperty _parentNewObjectsUnderRootProperty;
14+
SerializedProperty _parentNewObjectsUnderSceneContextProperty;
1515

1616
public override void OnEnable()
1717
{
1818
base.OnEnable();
1919

2020
_contractNameProperty = serializedObject.FindProperty("_contractNames");
2121
_parentNamesProperty = serializedObject.FindProperty("_parentContractNames");
22-
_parentNewObjectsUnderRootProperty = serializedObject.FindProperty("_parentNewObjectsUnderRoot");
22+
_parentNewObjectsUnderSceneContextProperty = serializedObject.FindProperty("_parentNewObjectsUnderSceneContext");
2323
}
2424

2525
protected override void OnGui()
@@ -28,7 +28,7 @@ protected override void OnGui()
2828

2929
EditorGUILayout.PropertyField(_contractNameProperty, true);
3030
EditorGUILayout.PropertyField(_parentNamesProperty, true);
31-
EditorGUILayout.PropertyField(_parentNewObjectsUnderRootProperty);
31+
EditorGUILayout.PropertyField(_parentNewObjectsUnderSceneContextProperty);
3232
}
3333
}
3434
}

UnityProject/Assets/Plugins/Zenject/Source/Install/Contexts/SceneContext.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ public class SceneContext : RunnableContext
2424
public static IEnumerable<DiContainer> ParentContainers;
2525

2626
[FormerlySerializedAs("ParentNewObjectsUnderRoot")]
27+
[FormerlySerializedAs("_parentNewObjectsUnderRoot")]
2728
[Tooltip("When true, objects that are created at runtime will be parented to the SceneContext")]
2829
[SerializeField]
29-
bool _parentNewObjectsUnderRoot;
30+
bool _parentNewObjectsUnderSceneContext;
3031

3132
[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")]
3233
[SerializeField]
@@ -94,10 +95,10 @@ public IEnumerable<string> ParentContractNames
9495
}
9596
}
9697

97-
public bool ParentNewObjectsUnderRoot
98+
public bool ParentNewObjectsUnderSceneContext
9899
{
99-
get { return _parentNewObjectsUnderRoot; }
100-
set { _parentNewObjectsUnderRoot = value; }
100+
get { return _parentNewObjectsUnderSceneContext; }
101+
set { _parentNewObjectsUnderSceneContext = value; }
101102
}
102103

103104
public void Awake()
@@ -230,7 +231,7 @@ public void Install()
230231
Assert.That(_decoratorContexts.IsEmpty());
231232
_decoratorContexts.AddRange(LookupDecoratorContexts());
232233

233-
if (_parentNewObjectsUnderRoot)
234+
if (_parentNewObjectsUnderSceneContext)
234235
{
235236
_container.DefaultParent = transform;
236237
}

0 commit comments

Comments
 (0)