Hello, I created a basic beat-em-up style combat game but if my enemies attack near each other they sometimes (most of the time but not always) freeze and can no longer move or change animations but continue to make attack hitboxes.
Here’s screenshots of my code, there is other code but it shouldn’t affect the enemies from what I can tell (and most of it was made after the bug started happening anyways). The only part that affects them is the Player attack, and the bug still occurs if I never attack.
Where do you change the orc animation from “OrcAttack” to anything else? If you don’t change it then the orcs will stay stuck in the loop creating attack hitboxes
Also, a few pointers:
You have 3 Repeat for each instance of Orc, 2 which move the orc towards the player. Combine these into 1 parent event, and the rest subevents. A “For each object” event can start to impact processing time.
Get rid of the Trigger once in this screen snip, it’s pointless. You only perform the actions this if the conditions are met, and in the actions you make a change to the animation so the conditions will not be met the next game frame:
Thanks so much - there’s a few "trigger once"s left from when I was troubleshooting on my own. I tried to take out most of them but missed a few. Those repeat “For each instance” are probably also from when I was experimenting to try and fix it.
As for when I change the animation from “OrcAttack” back to “Walk”, it’s the very last line in the screenshot, when the animation ends it is set back to “Walk”. I also tried adding the “Animation = OrcAttack” condition above “The animation of Orc is finished” but that didn’t change anything.
Sadly, condensing those “For each instance” and removing the “trigger onces” was not enough to fix the bug ;( but they do make the code cleaner at least.
Actually right as you made that reply I finally figured it out. I had a “trigger once” at the very bottom, the same event you missed initially. I’m pretty sure it was from the tutorial I followed. But once I removed it, the bug stopped - I haven’t seen any negative side effect yet. I think because it was only triggering once, it was only unfreezing one of the enemies and the other one was left stuck somehow. They were freezing at the end of the attack animation I believe, either way it seems to be solved (unless removing that trigger once broke something I haven’t seen yet, lol).
the Trigger once conditions in that was in the last event. If one orc’s animation finished, the event is triggered. If another orc’s animation finishes within a couple of game frames, the conditions are still considered to have been met, and the trigger once kicks in, preventing the event from actioning again. This is because every single trigger once gets an UID attached to it. Then, when the trigger is called, it store the UID in a storage of all the UID of the trigger once that have been called. If after 2 frames it hasn’t been called again, it is deleted from that storage. While it is in that storage, it will return false as a condition.
That wait action in the last event, it creates a thread for the event’s actions that follow it, and runs the actions in each thread after the thread wait has completed. Without the “trigger once” a thread is created for the action that kicks off 0.75 of a second’s worth of game frames later. At 60fps, that’s about 45 times threads created, all getting set off one after the other when the thread time is over. If you really want to delay between orc attack and walking, then try repeat the last orc attack game frame in the sprite’s animation a few times rather than use a wait action.
Thanks so much for your help. I probably would have taken a lot longer to find it if I wasn’t looking for "Trigger Once"s in my code. I went ahead and made that change to the wait action too. Honestly I have no idea what “threads created” and such means, I’m a total amateur, but hopefully it cleans up my game. Thanks again!
Think of a thread as a copy of the events which get run once the wait interval is finished for that copy of the events. So GDevelop in one game frame says “action these events once in 0.75 seconds from now”. In the next game frame, a fraction of a second later, GDevelop creates another thread (copy of the events) and sets those to be actioned in 0.75 seconds from the current time (which will be a fraction of a second after the first one).
GDevelop does that repeatedly until the conditions are no longer true. And then the threads get actioned once their time is up, which will be one after the other, but not all at once.