Skip to content

Manually initialize TimerManager #17

Description

@Petethegoat
Some objects were not cleaned up when closing the scene. (Did you spawn new GameObjects from OnDestroy?)
The following scene GameObjects were found:
TimerManager

If the first time a timer is registered is in the OnDisable or OnDestroy function, then it may create the TimerManager as a scene is closed (for example, when exiting playmode)

I simply added a method to initialize it manually. This could also use RuntimeInitializeOnLoadMethod and occur with no user action required.

/// <summary>/// Initializes the TimerManager, useful if your first Timer usage/// may otherwise be in OnDisable or OnDestroy, which may be called when exiting playmode./// </summary>publicstaticvoidInitializeManager(){if(Timer._manager==null){TimerManagermanagerInScene=Object.FindObjectOfType<TimerManager>();if(managerInScene!=null){Timer._manager=managerInScene;}else{GameObjectmanagerObject=newGameObject{name="TimerManager"};Timer._manager=managerObject.AddComponent<TimerManager>();GameObject.DontDestroyOnLoad(managerObject);}}}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions