# TMap data lost

**URL:** <https://forums.unrealengine.com/t/tmap-data-lost/134462>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [December 4, 2019, 4:06pm UTC](https://forums.unrealengine.com/t/tmap-data-lost/134462 "2019-12-04T16:06:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![beiju](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@beiju](https://forums.unrealengine.com/u/beiju)\
**Post date:** [December 4, 2019, 4:06pm UTC](https://forums.unrealengine.com/t/tmap-data-lost/134462/1 "2019-12-04T16:06:12Z")

</div>

I want make a struct use like Tree

this is My Struct

```auto

USTRUCT(BlueprintType)
struct ACTIONRTS_API FGenChamberInfo : public FTableRowBase
{
    GENERATED_BODY()
public:
    FGenChamberInfo()
    {}
    UPROPERTY(EditAnywhere, BlueprintReadOnly)
        FName StreamLevelName;

    UPROPERTY(EditAnywhere, BlueprintReadOnly)
        FChamberInfo CurrentRoomInfo;

    UPROPERTY(EditAnywhere, BlueprintReadOnly)
        int Index;

    //UPROPERTY(EditAnywhere, BlueprintReadOnly)
    // TMap<EDoorType, FGenChamberInfo> NextRoomForEditer;
    //UPROPERTY(EditAnywhere, BlueprintReadOnly)

    //UPROPERTY(EditAnywhere, BlueprintReadOnly)
    FGenChamberInfo* PreRoom;

    TMap<EDoorType, FGenChamberInfo*> NextRooms;

    //UFUNCTION(BlueprintCallable)
    FGenChamberInfo GetNextRoom(EDoorType doorType);

    /** Equality operators */
    bool operator==(const FGenChamberInfo& Other) const
    {
        return StreamLevelName == Other.StreamLevelName && Index == Other.Index;
    }
    bool operator!=(const FGenChamberInfo& Other) const
    {
        return !(*this == Other);
    }

};

```

This is How I Fill Tree

```auto

FGenChamberInfo AChamberGenerator::GenResult(int32 Index, FGenChamberInfo* LastChamber, EDoorType InDoorType, FGenChamberInfo& Result)
{
     Result = RandRoom(Index, LastChamber, InDoorType);

     UE_LOG(LogTemp, Warning, TEXT(" Index:%d RoomName: %s"),Index,*Result.StreamLevelName.ToString());
    if (LastChamber)
    {
        LastChamber->NextRooms.Add(InDoorType, &Result);
        Result.PreRoom = LastChamber;
        UE_LOG(LogTemp, Warning, TEXT(" AddNext:: %s "), *LastChamber->StreamLevelName.ToString());
    }
    if (Result.CurrentRoomInfo.OutDoorTags.Num() > 0)
    {
        Index++;
        for (EDoorType DoorType : Result.CurrentRoomInfo.OutDoorTags)
        {
            if (Index <= MaxRoomSize)
            {
                FGenChamberInfo TempResult = FGenChamberInfo();
                GenResult(Index, &Result, DoorType, TempResult);
            }
        }
    }
    return Result;
}

```

The result first node is ok,But second node’s `NextRooms` is Empty, The log says had fill value to `NextRooms`

---

<div class="post-metadata">

**Author:** ![andrea.b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@andrea.b](https://forums.unrealengine.com/u/andrea.b)\
**Post date:** [December 5, 2019, 8:25pm UTC](https://forums.unrealengine.com/t/tmap-data-lost/134462/2 "2019-12-05T20:25:09Z")

</div>

If you need something where you can store data statically I suggest you to define a class and derive it from UDataAsset, instead of using a struct that derives from FTableRowBase.  
I would do this because you cannot mark pointers that are not UObjects as UPROPERTY and you don’t gain any advangtages from reflections and GC.

Also, but I’m not sure, I think that TMap does not work properly with non-UObject pointers as well.

---

<div class="post-metadata">

**Author:** ![beiju](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@beiju](https://forums.unrealengine.com/u/beiju)\
**Post date:** [December 9, 2019, 2:56am UTC](https://forums.unrealengine.com/t/tmap-data-lost/134462/3 "2019-12-09T02:56:34Z")

</div>

> [@beiju](#):
>
> I want make a struct use like Tree
> 
> this is My Struct
> 
> ```html
> 
> USTRUCT(BlueprintType)
> struct ACTIONRTS_API FGenChamberInfo : public FTableRowBase
> {
> GENERATED_BODY()
> public:
> FGenChamberInfo()
> {}
> UPROPERTY(EditAnywhere, BlueprintReadOnly)
> FName StreamLevelName;
> 
> UPROPERTY(EditAnywhere, BlueprintReadOnly)
> FChamberInfo CurrentRoomInfo;
> 
> UPROPERTY(EditAnywhere, BlueprintReadOnly)
> int Index;
> 
> //UPROPERTY(EditAnywhere, BlueprintReadOnly)
> // TMap<EDoorType, FGenChamberInfo> NextRoomForEditer;
> //UPROPERTY(EditAnywhere, BlueprintReadOnly)
> 
> //UPROPERTY(EditAnywhere, BlueprintReadOnly)
> FGenChamberInfo* PreRoom;
> 
> TMap<EDoorType, FGenChamberInfo*> NextRooms;
> 
> //UFUNCTION(BlueprintCallable)
> FGenChamberInfo GetNextRoom(EDoorType doorType);
> 
> /** Equality operators */
> bool operator==(const FGenChamberInfo& Other) const
> {
> return StreamLevelName == Other.StreamLevelName && Index == Other.Index;
> }
> bool operator!=(const FGenChamberInfo& Other) const
> {
> return !(*this == Other);
> }
> 
> };
> 
> ```
> 
> This is How I Fill Tree
> 
> ```html
> 
> FGenChamberInfo AChamberGenerator::GenResult(int32 Index, FGenChamberInfo* LastChamber, EDoorType InDoorType, FGenChamberInfo& Result)
> {
> Result = RandRoom(Index, LastChamber, InDoorType);
> 
> UE_LOG(LogTemp, Warning, TEXT(" Index:%d RoomName: %s"),Index,*Result.StreamLevelName.ToString());
> if (LastChamber)
> {
> LastChamber->NextRooms.Add(InDoorType, &Result);
> Result.PreRoom = LastChamber;
> UE_LOG(LogTemp, Warning, TEXT(" AddNext:: %s "), *LastChamber->StreamLevelName.ToString());
> }
> if (Result.CurrentRoomInfo.OutDoorTags.Num() > 0)
> {
> Index++;
> for (EDoorType DoorType : Result.CurrentRoomInfo.OutDoorTags)
> {
> if (Index <= MaxRoomSize)
> {
> FGenChamberInfo TempResult = FGenChamberInfo();
> GenResult(Index, &Result, DoorType, TempResult);
> }
> }
> }
> return Result;
> }
> 
> ```
> 
> The result first node is ok,But second node’s `NextRooms` is Empty, The log says had fill value to `NextRooms`

The problem is Point not able when out work range, The memory is recycled when the function finish
