SendAIMessage, Behaviour Trees and SetFinishOnMessage in Blueprint

I was not able to find explanations about SendAIMessage and its proper use cases. Checking the source code just did get me deeper and deeper into stuff like FAIMessage, Braincomponent and so on… so getting somewhat lost here.

I’m confused about parameter and naming: Target is Pawn - so I thought I can use it to send a message to a BT from my pawn. Parameter Message Source does confuse me. It offers anything in the dropdown, even textures.

I would expect to be able to select a BT Task here as destination and in the BT Task, there’s a SetFinishOnMessage node - perfectly matching that.

I did a test, setting BT Task as destination in the source dropdown and reacting on this message in the BTTask - it worked.

So it looks to me like an alternative to stop a running task. Instead using a decorator and setting abort conditions, I just sent a message to the BT Task and it finished. But I’m not sure, if I’m misusing some mechanism here.

Is there anyone who can explain more in depth how this is meant to be used?

EDIT #1
BTW: Documentation/flyover help states the following for SetFinishOnMessage:

task execution will be finished (with result ‘Success’) after receiving specified message

The docs are not correct here, the real functionality is better: my test showed, that parameter Success in SendAIMessage can be used to determine, whether the BTTask should finish success or not.

1 Like

Really no one out there being able to throw some light on that SendAIMessage function? I have implemented this now in conjunction with my BTTask, and it works like a charm. No need for a decorator at all. I also tested decorator version, but I’m not sure, if this might introduce delays, while the message works immediately.

Left part in blue: my character moving along a spline, movement done in character tick. This movement is part of a BTTask - and I needed a way to make the task finish, once the character has finished its movement. In the BTTask, I use SetFinishOnMessage within Receive Event Execute AI, so this makes the task wait for that message and then finish.

Is this a valid use case? Is this the one and only use case? I did not find anything like “OnReceiveAIMessage” nodes, not in any blueprint, even the AI Controller BP does not offer that. I’d be really interested in this, because it looks like a powerful function

2 Likes