Verse Scenegraph Loops

I am new to Scene Graphs so I followed this tutorial (https://www.youtube.com/watch?v=mV6h4IQxuTk) on Sweep Hits but wanted to have the InputAwait function toggle loop instead of awaiting an input. I added two triggers one toggles off and other toggles on. However it just doesn’t work unless there’s a Agent:=InputTrig.PressedEvent.Await() after the loop, like in the original tutorial.

I imagine this is a simple thing I’m overlooking but I’ve been tinkering with this for hours and can’t figure it out. :melting_face:

Here is the script:


using { /Fortnite.com }
using { /Fortnite.com/Devices }
using { /Verse.org }
using { /Verse.org/SceneGraph }
using { /Verse.org/Assets }
using { /Verse.org/Simulation }
using { /UnrealEngine.com/Temporary/UI }
using { /Fortnite.com/Characters }
using { /UnrealEngine.com/Temporary/Diagnostics }
using { /Verse.org/SpatialMath }
using { /Verse.org/Colors }

XYZ<public> := import(/UnrealEngine.com/Temporary/SpatialMath)

my_debug_draw<public> := class(debug_draw_channel) {}

object_placer_component<public> := class<final_super>(component):

    @editable
    Trigger: trigger_device = trigger_device{}
    @editable
    Trigger2: trigger_device = trigger_device{}

    @editable
    PlaceablePrefab : Prefabs.P_TestBox = Prefabs.P_TestBox{}

    DebugDraw:debug_draw = debug_draw{Channel := my_debug_draw}


    InputAwait(mAgent : ?agent) <suspends>:void=
        if: 
            Agent := mAgent?
            FC:=Agent.GetFortCharacter[]
        then:
            race:
                block:
                    loop:
                        ViewRot := XYZ.FromRotation(FC.GetViewRotation())
                        ViewXform := transform:
                            Translation := XYZ.FromVector3(FC.GetViewLocation())
                            Rotation:= ViewRot
                        HitsGen := Entity.FindSweepHits(ViewXform.Rotation.GetForwardAxis() * 3000.0, ViewXform, collision_point{})
                        HitsArray:= for(Hit:HitsGen) do Hit
                        
                        if(FirstHit := HitsArray[0]):
                            DebugDraw.DrawLine(ViewXform.Translation, FirstHit.ContactPosition)

                            PlaceablePrefab.SetGlobalTransform of transform:
                                Translation:=FirstHit.ContactPosition
                        Sleep(0.5)
                block:
                    Trigger2.TriggeredEvent.Await()


    OnBeginSimulation<override>():void =
        (super:)OnBeginSimulation()

    OnSimulate<override>()<suspends>:void =
        Trigger.TriggeredEvent.Subscribe(StartLoop)

    StartLoop(mAgent:?agent):void=
        spawn. InputAwait(mAgent)