UPBGE Multiple messages received instantaneously

So I’ve run into an issue in which the game engine fails to process multiple of the same messages that are received at the same time.

My specific example is the death of an enemy. It should send a message telling the kill counter to increase by 1. If two enemies are killed within the same tick, it only processes one of the kills and the number only increases by 1.

I can attach a blend file if it helps, but I’ll hold off for now because its kind of a difficult scenario to recreate. Any thoughts?

Thanks in advance.

This is by design. When using logic bricks, you are using sensors. Sensors can only fire once per frame. So if you have a message sensor, only one message is required to make it fire, any subsequent message received on the same frame won’t have any effect: the sensor is already fired for that frame.

I don’t know if other people have different ideas, but you might want to look into Python.

Thanks for the feedback. I’ve discovered a workaround for my problem after a bit of experimenting. I’ll leave this post up I suppose, in case anyone has any insight into how to amend this issue in a non-specific context such as my own.

import bge
cont = bge.logic.getCurrentController()
own = cont.owner

messageSens = cont.sensors['Message'] 
if messageSens.positive:
    for message in messageSens.bodies:
        print(message) 
2 Likes

enemies got property health right?

so a property sensor -> less then 1-> and -> endobject

on the enemy, this way it will kill himself when hp drops below 1, so you don’t need messages for that job, but if you know a bit python then i would go for that.

1 Like

For those that don’t follow what this is for, BPR is showing how you can recieve multiple messages per frame, and this is the code that goes through each of them.

You could swap “print(message)” for something that increments the score.

2 Likes

In this case, you have to run this script as part of a Python Controller in script mode, attached to a message sensor named “Message”. The script will be triggered only once per tick (at most), but thanks to Python you can query how many messages were actually fired during that tick!

2 Likes