Is it a good idea putting a delay 0.2 after OnPossess event on AIController blueprint?

Hi, all.

I wanted to discuss what you think about adding a Delay node right after the Event OnPossess. My teacher told us it was advisable (I don’t really remember why), but in my case it just lead me to bugs because at some point I spawn enemies around the player (with RandomPointInNavigableRadius), so these enemies detect the player immediately with the Sight sense, so I set a Blackboard variable so the behaviour tree can move these enemies to the player. But in OnPossess I do some previous settings.

Now, if I add that delay, the OnTargetPerceptionUpdate triggers before the nodes at OnPossess (because they are delayed 0.2s) and, due to these previous settings not setting before, the nodes at OnTargetPerceptionUpdate fail and, until the enemies don’t detect the player again (the player must get far and approach again to them to be detected again) the AI behaviour doesn’t work.

Now, I deleted the delay and the AI works fine, so, in which cases it is more advisable to use this delay?

you could try replace delay with delayTillNextTick()

When you really need it :roll_eyes:

But if your original idea was for the code to work without delays, then you should think about why it became necessary.

In my practice, such delays were “needed” either during a network game (when the data did not arrive on time), or during Begin Play, when I needed a SPECIFIC order of calling.

But in both cases there are other, more correct ways to solve it, but they often require a little (and sometimes a lot) more effort, and the delay becomes (usually) the magic elixir of fixing everything. :grin: