Announcement

Collapse
No announcement yet.

TMap data lost

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    TMap data lost

    I want make a struct use like Tree

    this is My Struct



    HTML Code:
    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 Code:
    
    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`

    #2
    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.

    Comment


      #3
      Originally posted by beiju View Post
      I want make a struct use like Tree

      this is My Struct



      HTML Code:
      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 Code:
      
      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

      Comment

      Working...
      X