Skip to content

Commit 0600101

Browse files
authored
Merge pull request #18 from lfeq/feature-support-child-dontdestroyonload
Enhancement: Support DontDestroyOnLoad for Child GameObjects
2 parents b6c92ae + 7bed0ce commit 0600101

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Runtime/Scripts/PersistentMonoSingleton.cs

+9
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,19 @@ namespace UnityCommunity.UnitySingleton
88
/// <typeparam name="T"></typeparam>
99
public abstract class PersistentMonoSingleton<T> : MonoSingleton<T> where T : MonoSingleton<T>
1010
{
11+
/// <summary>
12+
/// if this is true, this singleton will auto detach if it finds itself parented on awake
13+
/// </summary>
14+
[Tooltip("if this is true, this singleton will auto detach if it finds itself parented on awake")]
15+
[SerializeField] private bool UnparentOnAwake = true;
16+
1117
#region Protected Methods
1218

1319
protected override void OnInitializing()
1420
{
21+
if (UnparentOnAwake) {
22+
transform.SetParent(null);
23+
}
1524
base.OnInitializing();
1625
if (Application.isPlaying)
1726
{

Runtime/Scripts/PersistentMonoSingleton.cs.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)