Issue with using a sleep call in a branch in verse

Please select what you are reporting on:

Verse

What Type of Bug are you experiencing?

Verse

Summary

I was recently writing some verse to play vfx_spawner_device for a few seconds as part of an in game event occurring. I decided to use the opportunity to experiment with the branch version of structured concurrency. I wrote something like the simplified snippet below in the steps to reproduce, but unfortunately the vfx disable call never happens (nor does any code I put inside the branch after the sleep).

Steps to Reproduce

TriggerEvent() : void =
{
# Do stuff before VFX start

# Trigger VFX
if ( VFX_DurationSecs > 0.0 )
{
	branch
	{
		VFX.Enable()
		Sleep(VFX_DurationSecs)
		VFX.Disable()
	}
}

# Do other stuff in parallel with VFX

}

Expected Result

The vfx would start and play for the specified duration and then stop, and the ā€œother stuff in parallelā€ would occur while the vfx plays.

Observed Result

The vfx starts, and the ā€œother stuff in parallelā€ does run in parallel but the vfx disable call (or any other code I tried after the sleep) never executes.

Platform(s)

PC

This issue is still happening as of 8/16/2024. It’s frustrating because we are encouraged to use branch as much as possible instead of spawn.

The status of FORT-779847 incident has been moved from ā€˜Needs Triage’ to ā€˜Backlogged’.

Is anyone else still having this issue? This thread is from February.

Yes, I have just seen this issue (8/21/24). Using a Sleep() anywhere downstream of a ā€˜branch’ call will still end that path of code execution.

This is actually not a bug but is the way ā€œbranchā€ is supposed to behave. Conan Reis discusses this in a video that I just watched (https://www.youtube.com/watch?v=B3WiSgKXsrg). See around the 6:45 mark of the video. Conan specifically says using branch can be tricky and devs need to understand its underlying behavior.

In a nutshell: When branch is used, any branch functions will be cancelled if the function which called them finishes before each branched function finishes. So, the Sleep calls were not exposing a bug, but instead just causing this expected behavior to surface.

I feel this behavior should be better documented on the Verse docs pages.

1 Like