hackerspace-ntnu / hackerspace-ntnu/Red-Planet-Rampage

Singleton controlflow (script execution order)

Open
#30 0 comments 0 reactions 0 assignees View on GitHub
feature
Dominant language
C#
Stars
32
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Singletons currently in the project are somewhat unsafe, considering they can be disabled. They also don't follow any standard on "when" they're initialised, leading to potentially unpredictable/unwanted behaviour.

---

**Safety**:
A singleton script should consider the scenario where either the component itself or the game object it is attached to is disabled.
As the singleton instance can be accessed from _anywhere_ at any time, we should handle the (likely unwanted) scenario where a singleton component is being disabled (either through the game object being disabled or the component itself being explicitly disabled).

- Solution: do something in `OnDisable` in any singleton scripts - whether that be a warning log entry or otherwise, do something!

---

**Initialisation**:
As a singleton instance-field initialisation relies solely on itself, there is no reason - as I see it - for why any and all singletons should not be initialised in `OnEnable`, rather than in any of the later component messages. This may aid in reducing future annoyances in script execution order.

- Solution: move static field initialisation (singleton) to `OnEnable`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.