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)