I'm developing an inventory ui that relies heavily on custom scripting/unity ui. I'm doing some initial testing to get familiarized with the built in AC events, specifically "OnMenuTurnOn" from here:
https://adventurecreator.org/scripting-guide/class_a_c_1_1_event_manager.html#a25370a85c31f7e120e13c2c4d2643692
For whatever reason, the function is firing twice the first time opening the menu, then 4 times the second time, 6 the third, and so on.
Here's my test script:
private void MenuTurnOn(AC.Menu _menu, bool isInstant)
{
if(_menu.title == "Inventory")
Debug.Log("MenuTurnOn. Menu: " + _menu.title + ", isInstant: " + isInstant);
else
{
return;
}
}
private void OnEnable()
{
EventManager.OnMenuTurnOn += MenuTurnOn;
}
private void OnDisable()
{
EventManager.OnMenuTurnOff -= MenuTurnOn;
}
I'm drawing a blank to where I'd even begin to troubleshoot this issue. Any ideas on what I could be doing wrong?
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
If it's being called twice each time, where is the script placed, and how many instances of this script are present in the scene? Check that you don't have two instances of it enabled at once.
Also, what is your AC version? An issue related to this was addressed in v1.82.2.
I was in fact on an old version, but I've updated to 1.82.2 and no luck. The script is on the root canvas of the prefab which is linked to the custom AC menu. I've triple checked the prefab is not placed within the scene, and AC is only spawning one instance of the menu under "DontDestroyOnLoad" once in play mode (and opening menu). I've also tried multiple scenes with no luck.
Oh wait, it was the last function having:
EventManager.OnMenuTurnOff -= MenuTurnOn;
I'm unregistering my custom function from OnMenuTurnOn in the OnDisable function now. I get where my mind was going, but at least it was a simple mistake.