Skip to content

Potential race condition in AbstractSingleton #49

@SorraTheOrc

Description

@SorraTheOrc

On Discord prof_jerz reported that:

NullReferenceException: Object reference not set to an instance of an object
WizardsCode.Stats.Brain.OnEnable () (at /Users/jerz/Downloads/Character-Unity-Package-main/Character/Scripts/Runtime/Stats/Brain.cs:152)
UnityEngine.Object:Instantiate(GameObject, Vector3, Quaternion)
UMA.UMARandomAvatar:GenerateRandomCharacter(Vector3, Quaternion, String) (at Assets/UMA/Core/Extensions/DynamicCharacterSystem/Scripts/UMARandomAvatar.cs:79)
UMA.UMARandomAvatar:Start() (at Assets/UMA/Core/Extensions/DynamicCharacterSystem/Scripts/UMARandomAvatar.cs:58)

This sounds like a race condition since ActorManager.Instance is accessed in Brain.OnEnable and set in ActorManager.OnEnable.

If that is correct you can resolve this by making ActorManager execute earlier than Brain, this will almost certainly work if your goal is to just get going.

A better solution would be to move the setting of Instance in https://github.com/TheWizardsCode/Character-Dev/blob/main/Assets/Wizards%20Code/Character%20AI/Character/Scripts/Runtime/Utility/AbstractSingleton.cs into Awake rather than OnEnable. However, if any of the implementations of AbstractSingletong provide an implementation of Awake these would also need to be marked as Override with base.Awake() being added. So that would require a little testing.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions