Skip to content

Commit

Permalink
Fixes to project template MonoBehaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
Zingabopp committed Jan 17, 2020
1 parent 8972371 commit ddd9ecc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions BSIPA Plugin (Core)/MonobehaviourTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ private void Awake()
// For this particular MonoBehaviour, we only want one instance to exist at any time, so store a reference to it in a static property
// and destroy any that are created while one already exists.
if (instance != null)
{
Logger.log?.Warn($"Instance of {this.GetType().Name} already exists, destroying.");
GameObject.DestroyImmediate(this);
return;
}
GameObject.DontDestroyOnLoad(this); // Don't destroy this object on scene changes
instance = this;
Logger.log?.Debug($"{name}: Awake()");
Expand Down
4 changes: 4 additions & 0 deletions BSIPA Plugin (Disableable)/MonobehaviourTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ private void Awake()
// For this particular MonoBehaviour, we only want one instance to exist at any time, so store a reference to it in a static property
// and destroy any that are created while one already exists.
if (instance != null)
{
Logger.log?.Warn($"Instance of {this.GetType().Name} already exists, destroying.");
GameObject.DestroyImmediate(this);
return;
}
GameObject.DontDestroyOnLoad(this); // Don't destroy this object on scene changes
instance = this;
Logger.log?.Debug($"{name}: Awake()");
Expand Down

0 comments on commit ddd9ecc

Please sign in to comment.