Hey guys, so I have an Inventory which is an ActorComponent and in which I have a TArray of struct:
UPROPERTY(BlueprintReadWrite, EditAnywhere, meta=(AllowPrivateAccess = "true"), Replicated)
TArray<FPlayerCharacteristics> PlayersCharacteristics;
Here is what the struct is made of:
USTRUCT(BlueprintType)
struct FPlayerCharacteristics
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadOnly)
TObjectPtr<APlayerState> OwningPlayer;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FCharacteristicsData> Characteristics;
};
I want to initialise my TArray with that function, which would just create an empty table that I could be able to find and populate later thanks to the corresponding PlayerState.
In my blueprint where I initialise my player, I run that function on the server side which is why I set my variable to Replicated in UPROPERTY().
void UCharacteristicsInventory::InitCharacteristics(UObject* WorldContextObject, ABaseCharacter* _OwningPlayer)
{
if (WorldContextObject->GetWorld() == nullptr) return;
OwningPlayer = _OwningPlayer;
for (auto PlayerState : WorldContextObject->GetWorld()->GetGameState()->PlayerArray)
{
if (PlayerState != OwningPlayer->GetPlayerState())
{
FPlayerCharacteristics* PlayerCharacteristics = new FPlayerCharacteristics();
PlayerCharacteristics->OwningPlayer = PlayerState;
TArray<FCharacteristicsData>* NewArray = new TArray<FCharacteristicsData>();
PlayerCharacteristics->Characteristics = *NewArray;
PlayersCharacteristics.Add(*PlayerCharacteristics);
}
}
}
The problem is that it seems to be the same array for every players, when I launch the game here is what I get in the debug:
But when I press a key on each player to see what their TArray is containing, here is what I get:
I tried to make this TArray a pointer, it was working but it was instantly garbage collected because it wasn’t marked as UPROPERTY()
I would like to know how I could make my TArray unique for each players, thanks in advance!
I hope I made it understandable enough so someone can help me, if you need further information, let me know and I’ll do my best!