verse code help needed

I have a problem with a verse code that has a model that is put instead of the player’s skin but when the player dies the model is still there and it causes the game to crash because the verse code is still running on loop. Somebody said this in a youtube comment: “managed to fix it, just delete the model when the player using it is killed if that makes sense”. But I dont know how to do it. Can someone help me please?
Here’s the code:

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

See Create Your Own Device Using Verse in Unreal Editor for Fortnite | Fortnite Documentation | Epic Developer Community for how to create a verse device.

A Verse-authored creative device that can be placed in a level

custom_model_device := class(creative_device):

@editable
FreddyProp : creative_prop = creative_prop{}
@editable
Mutator : mutator_zone_device = mutator_zone_device{}
@editable
RunningCinematic : cinematic_sequence_device = cinematic_sequence_device{}

var IsCinematicPlaying : logic = false

UpdateModel ( Agent : agent )<suspends> : void =
    if (FortCharacter := Agent.GetFortCharacter[]):
        FortCharacter.Hide()
        
        branch:
            loop:
                if (FortCharacter.IsActive[]):
                    Sleep(0.0)
                    PlayerPos := FortCharacter.GetTransform().Translation
                    FreddyPos := FreddyProp.GetTransform().Translation

                    DistanceFromPlayer := Distance(PlayerPos, FreddyPos)
                    
                    DirectionFreddyToPlayer := PlayerPos - FreddyPos

                    Angle := ArcTan(DirectionFreddyToPlayer.X, DirectionFreddyToPlayer.Y) - 3.14 / 2.0

                    NewRotation := MakeRotation( vector3{ X := 0.0, Y := 0.0, Z := -1.0} , Angle) 

                    FreddyProp.MoveTo(PlayerPos, NewRotation, 0.15)
        
        loop:
            if (not FortCharacter.IsActive[]):
                break
            Sleep(0.0)
            IsSprintingTuple := FortCharacter.SprintedEvent().Await()
            if (IsSprintingTuple(1)?):
                RunningCinematic.Play()
            else:
                RunningCinematic.Stop()

HandleAgentTrigger ( Agent : agent ) : void =
    spawn:
        UpdateModel(Agent)
HandlePlayerSprint( Agent : agent ) : void =
    {}
OnBegin<override>()<suspends>:void=
    Mutator.AgentEntersEvent.Subscribe(HandleAgentTrigger)
1 Like

By-The-Way, the person you copied from got ArcTan backwards. :wink:
Or, I guess you could say: since 1961 the function itself is the one that’s backwards
ArcTan(Y, X) *because that’s how “atan2” is written on paper… (not X,Y!) so you might wanna swap that.

Don’t be afraid to try out some of the official guides - they might not seem related at first, but if you look through their code for the tuts and example maps you will start making sense of things over time.


Take a quick read about “RACE” concurrency (just 4 minutes of your time, trust me!) - it might not make much sense at first, but at least you will know what is in the page if you need to refer back later.

once you roughly understand that BRANCH and RACE are similar…

  1. You can simply swap the line branch: for race: .
  2. Then, indent your second loop.
    Now you have 2 “blocks” of code running in your RACE.
  3. Now you can easily add a 3rd “block” of code to that race: FortCharacter.EliminatedEvent.Await()

Whichever of the 3 code-blocks exits first, will exit out of UpdateMode() for the others.

Easy!

Final code:

if (FortChar...)
    FortChar.Hide()...
    race:
        loop:    #first block    (physics code)
            if (...IsActive[]):
                ....
        loop:    #second block    (run-animation code)
            if (not ...IsActive[])
                ...
            ...
        block:    #new/third block
            FortCharacter.EliminatedEvent.Await()

Note that your method will lag a bit in multiplayer, but if you got this far, you are doing well!
As an extra practice, at the end of UpdateModel() perhaps consider moving freddy out of the way FreddyProp.MoveTo(vector3{}, rotation{}, 0.15) (put whatever co-ords you like in the vector3{})