#Restart being called twice

1 messages · Page 1 of 1 (latest)

main comet
#

so the new code

#

that's about it

#

nothing else is related

#

and the output after canceling a valve minigame

#

and the output after completing the valve minigame

polar dragon
# main comet

Okay, so, let's break this down. Gonna add some braces to make it more visible what's happening here

ValveMinigame gets Stop called on it
{
  ValveMinigame gets Stop called on it
  {
    One of the Stops reaches Restart and calls it
  }
  PinMinigame gets Stop called on it
  {
    PinMinigame's Stop reaches Restart and calls it
  }
  The other Valve Stop reaches Restart and calls it
}
PinMinigame gets Stop called on it
{
  PinMinigame's Stop reaches Restart and calls it
}  
#

So there's some layering going on and Stop is definitely happening twice on each

main comet
#

yup, twice on each

polar dragon
# main comet

So it's definitely related to cancelling, since the "Completion" print looks fine.

main comet
#

these are the only methods that i subscribe to the exit event

#
            Player.inputSystem.OnMinigameCancelDo += Stop;
            Player.inputSystem.OnMinigameCancelDo += OnPlayerExitInvoke;
#
        private void OnPlayerExitInvoke()
        {
            OnPlayerExit?.Invoke();
        }
#

and OnPlayerExit

polar dragon
#

Wait

main comet
#

is just moving the camera back to the player

polar dragon
#

I got it

main comet
#

not related

polar dragon
#

Both are using the same Player

main comet
#

thats right

#

so?

#

oooh

polar dragon
#

This line here is in Minigame

main comet
#

i got ya

polar dragon
#

They share the same one

#

So this one Player gets both cancel events mapped to it

main comet
#

so each minigame should have cached it's own player?

polar dragon
#

This line is run on each of them

main comet
polar dragon
#

So, whenever any minigame starts, it immediately adds its cancel functions to the GameManager's player

main comet
#

yup i got i now

#

just, how do i fix that

polar dragon
#

And then pressing cancel calls them all

#

You should only add those listeners when a Minigame actually starts, and remove them when it stops

#

I can ponder this a bit more later but I have to do some actual day job stuff for a bit

main comet
#

i think i got i now in my head

#

thank you so much for your engagement

main comet
#

just wanted to let you know that you were right and I've managed to fix the issue and refactor my minigame system, so like you said every time i start new minigame i remove all listeners and add just the neccesary ones