# despawn pets

**URL:** <https://forums.unrealengine.com/t/despawn-pets/2006155>\
**Category:** Verse\
**Tags:** question, fortnite\
**Created:** [September 5, 2024, 8:45am UTC](https://forums.unrealengine.com/t/despawn-pets/2006155 "2024-09-05T08:45:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![flame\_i\_am](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@flame\_i\_am](https://forums.unrealengine.com/u/flame_i_am)\
**Post date:** [September 5, 2024, 8:45am UTC](https://forums.unrealengine.com/t/despawn-pets/2006155/1 "2024-09-05T08:45:49Z")

</div>

I want to make the pet despawn when a button is pressed, but i do not know how to. I tried to figure it out, but i cant. Here is the code if anyone is willing to help:

```auto
spawn_pet_device2 := class(creative_device):
    var Players : []player = array{}
    @editable
    SpawnEgg : conditional_button_device = conditional_button_device{}

    @editable
    DebbyAsset : creative_prop_asset = DefaultCreativePropAsset
    
    
    SpawnDebby( Agent : agent ) : void =
        if (FortCharacter := Agent.GetFortCharacter[]):
            PlayerPos := FortCharacter.GetTransform().Translation
            PlayerForward := FortCharacter.GetViewRotation().GetLocalForward() * 300.0
            DebbySpawnPos := PlayerPos + PlayerForward
            
            Result := SpawnProp(DebbyAsset, DebbySpawnPos, rotation{})
            if (SpawnedProp := Result(0)?):
                spawn:
                    PetFollowsPlayer(FortCharacter, SpawnedProp)
                    
    PetFollowsPlayer( FortniteCharacter : fort_character, CreativeProp : creative_prop)<suspends> : void =
        loop:
            Sleep(0.0)
            PlayerPos := FortniteCharacter.GetTransform().Translation
            DebbyPos := CreativeProp.GetTransform().Translation

            DistanceFromPlayer := Distance(PlayerPos, DebbyPos)
            Time := DistanceFromPlayer / 350.0
            CreativeProp.MoveTo(PlayerPos, rotation{}, Time)

    OnBegin<override>()<suspends>:void=
        set Players = GetPlayspace().GetPlayers()
        SpawnEgg.ActivatedEvent.Subscribe(SpawnDebby)

```

---

<div class="post-metadata">

**Author:** ![Mapshot\_Agency](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mapshot_agency/32/700660_2.png) [@Mapshot\_Agency](https://forums.unrealengine.com/u/Mapshot_Agency)\
**Post date:** [September 5, 2024, 8:50am UTC](https://forums.unrealengine.com/t/despawn-pets/2006155/2 "2024-09-05T08:50:38Z")

</div>

Hi!

Despawning as in removing it? Then I would use the “Dispose” function. This disposes the object. Any reference to it can be later checked for “IsDisposed” to ensure that no more “MoveTo” functions are called on the disposed object.

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/0/8/f08dbcb682eb11e664b12cce7aa828bacb7d08b8.png)

---

<div class="post-metadata">

**Author:** ![flame\_i\_am](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@flame\_i\_am](https://forums.unrealengine.com/u/flame_i_am)\
**Post date:** [September 5, 2024, 3:50pm UTC](https://forums.unrealengine.com/t/despawn-pets/2006155/3 "2024-09-05T15:50:13Z")

</div>

i do not know how to implement this into the code, but ty for the advice

---

<div class="post-metadata">

**Author:** ![Mapshot\_Agency](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mapshot_agency/32/700660_2.png) [@Mapshot\_Agency](https://forums.unrealengine.com/u/Mapshot_Agency)\
**Post date:** [September 6, 2024, 11:03am UTC](https://forums.unrealengine.com/t/despawn-pets/2006155/4 "2024-09-06T11:03:47Z")

</div>

In your example, it would simply be “CreativeProp.Dispose()”  
Same as you would use the “MoveTo”

If you want a separate function to despawn it, you would have to save the reference at the top of the class so you can access it there (or pass it through the function).
