Cyclops Manager Origin Story - PrimeSonic/PrimeSonicSubnauticaMods GitHub Wiki

The CyclopsManager was a design pattern born out of necessity.
When modded Buildables were newly constructed inside the Cyclops or were being loaded from save data,
it was often the issue that the Buildable's main Monobehavior wasn't able to find the Cyclops SubRoot by looking through its own parent components.

// From the buildable's main MonoBehavior
private void Start()
{
    SubRoot cyclops = this.gameObject.GetComponentInParent<SubRoot>();
    // Searching from child to parent would actually return null even though the monobehavior is in a Cyclops

However, it was possible to find the Buildable's component by starting at the Cyclops SubRoot and looking through its child components.

// From the Aux Cyclops Manager
internal void Find()
{
    SubRoot cyclops = Cyclops;
    MyCyclopsBuildable[] buildables = cyclops.GetAllComponentsInChildren<MyCyclopsBuildable>();
    // Searching from parent to child would return the monobehaviors in the Cyclops they couldn't find themselves

Because of these complications, a new design pattern was made to help link Buildables with their parent Cyclops.
You will see this pattern used in the CyclopsNuclearReactor and CyclopsBioReactor.

The pattern would go on to have a few more uses, but this is where it started.

⚠️ **GitHub.com Fallback** ⚠️