Part of tree not aborted in time

justinhd

New member
Hello,

I have the following example tree as a test:

KJp72Wb.png

(this isn't my real tree of course)

In the area circled with 1, I log the value of a variable when it's empty. No problems so far. When it's empty, my log gets spammed full with empty strings.

In area 2, when the space key is down, I set the string variable to "Not Empty". The other area is just used for making the string empty again when I press a different button, but that's not important.

I expect that the log in part 1 will always log empty strings, because of the conditional abort. However, when I press Space, I see the log "Not Empty" appear. I've recorded a video that shows this: https://drive.google.com/file/d/1CfvLaeGlB72grhjjSrkMBQbOTwt2lEO0/view

What can I do to not have this "Not Empty" log appear when it already uses a conditional abort?

In my real game, part 2 stores a target player that's in range and sight once in a while. Part 1 then engages with this enemy (melee, shoot, throw grenade etc.). Because part 2 sometimes sets the target player to null when there's no target in range, I now have a null reference when using the target player in part 1. As a temporal solution, I have to null check everywhere in part 1 when I use the target player, but I rather have the conditional abort handle that.
 
It's tough to tell without playing it but how is the string set? It looks like you are setting it in branch 2 so that is why the log outputs it.
 
Yes, I set the string to "Not Empty" in part 2. But I don't understand why part 1 logs my not empty string, while it should only log it when the string is empty. Sorry, it's a bit of a weird example scene that I quickly put together. I've uploaded my scene here: https://drive.google.com/file/d/1racJ0mehlrysKZCYSypQed1KcOGJJtY5/view?usp=sharing

You only need to re-import the Behavior Designer Runtime Source to make the scene work. The tree is on the GameObject 'Cube'.

Enter playmode and see the "(null)" spam (because the value is initially null, not empty). Press Space to see "Not Empty" appear once. Pressing Escape when make the string empty, thus the log gets spammed with empty strings "".

My expected behavior is to never see "Not Empty" appear in the log because of the conditional abort.
 
I tried to import your Unity Package into Unity 2018.3 but it failed to import. Maybe the file got corrupted?
 
That would be why :)

I see what you are saying now. The reason that this is occurring is because of the execution order between conditional aborts and the rest of the tree. Conditional aborts are evaluated first, so your Is Null Or Empty check will return success before the string is set when the spacebar is checked. If you place everything under a parallel task or everything under a conditional abort then the execution order will match up.
 
Ah, I see. But I'm not really sure how I can fix this in the tree. Moving everything under the same parallel task is still causing the same behavior:

MbWhyqp.png


Otherwise, I think I will do part 2 of this example in the Update-loop of my GameObject then, so the tree will no longer change the string somewhere else. This should also be doable in my real game. But I'm still curious if it is possible to fix it in the tree.
 
You're running into the same situation with that tree. The issue is performing some sort of under the regular update loop and checking for that action within conditional aborts. If for example you changed Get Key to Is Key Down and used a conditional abort to determine if the string should be set then it would work.
 
Top