# Issue disposing creative\_prop\_asset stored in array

**URL:** <https://forums.unrealengine.com/t/issue-disposing-creative-prop-asset-stored-in-array/1265454>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [August 18, 2023, 11:37pm UTC](https://forums.unrealengine.com/t/issue-disposing-creative-prop-asset-stored-in-array/1265454 "2023-08-18T23:37:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![\_D\_27](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@\_D\_27](https://forums.unrealengine.com/u/_D_27)\
**Post date:** [August 18, 2023, 11:37pm UTC](https://forums.unrealengine.com/t/issue-disposing-creative-prop-asset-stored-in-array/1265454/1 "2023-08-18T23:37:55Z")

</div>

I am creating assets in Verse and storing them in a one dimensional array. This example creates 10 assets. I then dispose of some of them randomly. The tiles that match the criteria for disposal are disposed. The problem is that other that don’t fit the criteria are also disposed even though there is no print out to mark the disposal.

I adapted this code from a youtuber’s version related to two dimensional arrays. His works and mine seems to do way more than desired.

Any ideas why more tiles than requested are destroyed?

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

game\_device := class(creative\_device):

```
# asset is used in each tile cell
@editable var TileAsset : creative_prop_asset := DefaultCreativePropAsset

# single dimension array for testing tile asseet creation/disposal
var TileArray: []?creative_prop = array{}

OnBegin<override>()<suspends>:void=
    Print("onBegin")
    GenTiles(10)
    Sleep(5.0)
    DisposeRandomTile()

CreateCell(Index:int):?creative_prop=
    Spacer := 610.0
    if (Xp := float[Index * Spacer], Yp := 0.0):
        return SpawnProp(TileAsset, vector3{X := Xp, Y := Yp, Z := 140.0}, IdentityRotation())(0)
    else:
        return false

DisposeRandomTile()<suspends>:void=
    for (Index := 0..TileArray.Length - 1):
        if (Tile := creative_prop[TileArray[Index]?]):
            Rand := GetRandomFloat(0.0, 3.0)
            Print("Cell [{Index}] with Rand: {Rand}")
            if (Rand <= 1.0):
                Tile.Dispose()
                Print("Disposing cell: [{Index}] because {Rand} <= 1.0")

GenTiles(Number:int):void=
    set TileArray = 
        for (Index := 0..Number - 1):
            CreateCell(Index)

```

---

<div class="post-metadata">

**Author:** ![\_D\_27](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@\_D\_27](https://forums.unrealengine.com/u/_D_27)\
**Post date:** [August 22, 2023, 2:22pm UTC](https://forums.unrealengine.com/t/issue-disposing-creative-prop-asset-stored-in-array/1265454/2 "2023-08-22T14:22:45Z")

</div>

I found a fix for my issue. It involves checking for a valid item before attempting to dispose of it. Please see DisposeRandomTile() for the the changes.

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

log\_game\_device := class(log\_channel){}

game\_device := class(creative\_device):

```
Logger: log = log{Channel := log_game_device}

# asset is used in each tile cell
@editable var TileAsset : creative_prop_asset := DefaultCreativePropAsset

var Spacer : float = 610.0

# single dimension array for testing tile asseet creation/disposal
var TileArray: []?creative_prop = array{}

OnBegin<override>()<suspends>:void=
    Print("onBegin")
    GenTiles(10)
    Sleep(5.0)
    DisposeRandomTile()

CreateCell(Index:int):?creative_prop=
    if (Xp := float[Index * Spacer], Yp := 0.0):
        return SpawnProp(TileAsset, vector3{X := Xp, Y := Yp, Z := 140.0}, IdentityRotation())(0)
    else:
        return false

DisposeRandomTile()<suspends>:void=
    for (Tile : TileArray){
        if (Prop := creative_prop[Tile?]):
            if (Prop.IsValid[]):
                Rand := GetRandomFloat(0.0, 3.0)
                if (Rand <= 1.0):
                    Prop.Dispose()
                    Print("Disposing of Prop/Tile because {Rand} <= 1.0")
    }

GenTiles(Number:int):void=
    set TileArray = 
        for (Index := 0..Number - 1):
            CreateCell(Index)

```

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [September 21, 2023, 2:23pm UTC](https://forums.unrealengine.com/t/issue-disposing-creative-prop-asset-stored-in-array/1265454/3 "2023-09-21T14:23:19Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
