ow-mods/owml

ModHelper.Events.Event does not trigger reliably

sandsalamand opened this issue · 1 comments

Here is an example to demonstrate:

private void Start()
{			
        ModHelper.Events.Subscribe<FogLight>(Events.BeforeAwake);
	ModHelper.Events.Subscribe<FogLight>(Events.BeforeStart);
	ModHelper.Events.Subscribe<FogLight>(Events.BeforeEnable);
	ModHelper.Events.Subscribe<FogLight>(Events.AfterAwake);
	ModHelper.Events.Subscribe<FogLight>(Events.AfterStart);
	ModHelper.Events.Subscribe<FogLight>(Events.AfterEnable);
	ModHelper.Events.Event += OnEvent;
}

private void OnEvent(MonoBehaviour behaviour, Events ev)
{
	switch (behaviour)
	{
		case FogLight fogLight:
			ModHelper.Console.WriteLine("FogLight event = " + ev.ToString());
			break;
	}
}

This will only print "FogLight event = BeforeStart" and "FogLight event = AfterStart". No other Awake or Enable events are passed through.

From discussing this on Discord, it sounds like nobody uses this method, so if this is deemed to be unworthy of fixing, then my suggestion would be to modify the wiki to clarify exactly how unreliable ModHelper.Events is.

I think we should straight up obsolete these methods, since they work unreliably as you said and are completely inferior to just using patches with HarmonyHelper (or better yet, with HarmonyX)