Handling dead references when resetting objects. (#421)

* fix: handling dead references when resetting objects. (#417)

* fix: wrong state checked in AtomEvent reset (#403)

* fix: make AtomValueList compatible with disabled domain reload (#419)
fix: AtomValueList now resets runtime modifications (#418)

* fix: handling dead references when resetting objects for AtomValueList. (#417)

* removed the dead-reference handling (#417)
- this will be addressed in (#421)
compacted the Playmode state change

* Remove Atom types from their _instances lists OnDisable()

* Added disclaimer / comment regarding the solution

---------

Co-authored-by: Adam Ramberg <adam@mambojambostudios.com>
This commit is contained in:
Soraphis 2023-08-04 23:19:42 +02:00 committed by GitHub
parent 0899d4113d
commit 2d2ae9b12f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 5 deletions

View File

@ -76,6 +76,11 @@ namespace UnityAtoms
private void OnDisable()
{
// NOTE: This will not be called when deleting the Atom from the editor.
// Therefore, there might still be null instances, but even though not ideal,
// it should not cause any problems.
// More info: https://issuetracker.unity3d.com/issues/ondisable-and-ondestroy-methods-are-not-called-when-a-scriptableobject-is-deleted-manually-in-project-window
_instances.Remove(this);
// Clear all delegates when exiting play mode
UnregisterAll();
}

View File

@ -54,8 +54,9 @@ namespace UnityAtoms
private static HashSet<AtomValueList<T, E>> _instances = new HashSet<AtomValueList<T, E>>();
#endif
protected virtual void OnEnable()
protected override void OnEnable()
{
base.OnEnable();
#if UNITY_EDITOR
if (EditorSettings.enterPlayModeOptionsEnabled)
{
@ -67,6 +68,15 @@ namespace UnityAtoms
#endif
}
private void OnDisable()
{
// NOTE: This will not be called when deleting the Atom from the editor.
// Therefore, there might still be null instances, but even though not ideal,
// it should not cause any problems.
// More info: https://issuetracker.unity3d.com/issues/ondisable-and-ondestroy-methods-are-not-called-when-a-scriptableobject-is-deleted-manually-in-project-window
_instances.Remove(this);
}
#if UNITY_EDITOR
private static void HandlePlayModeStateChange(PlayModeStateChange state)
{

View File

@ -32,7 +32,7 @@ namespace UnityAtoms
Cleared.Raise();
}
}
private void OnEnable()
protected virtual void OnEnable()
{
if (_startCleared)
{

View File

@ -154,6 +154,14 @@ namespace UnityAtoms
#endif
}
private void OnDisable()
{
// NOTE: This will not be called when deleting the Atom from the editor.
// Therefore, there might still be null instances, but even though not ideal,
// it should not cause any problems.
// More info: https://issuetracker.unity3d.com/issues/ondisable-and-ondestroy-methods-are-not-called-when-a-scriptableobject-is-deleted-manually-in-project-window
_instances.Remove(this);
}
/// <summary>
/// Set initial values

View File

@ -1,10 +1,8 @@
using System;
using System.Transactions;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityAtoms.BaseAtoms;
using UnityAtoms;
namespace UnityAtoms.FSM
{
@ -68,7 +66,7 @@ namespace UnityAtoms.FSM
protected override void OnEnable()
{
base.OnEnable(); // handles resetting and initial values and all that.
if (CompleteCurrentTransition != null && CompleteCurrentTransition.ReplayBufferSize > 0)
{
Debug.LogWarning("The Complete Current Transition event had a replay buffer size great than 0, which would cause unwanted behaviour. Setting it to 0 in order to avoid unexpected behaviour.");