Hey,
Recently I’ve tried to replicated a UPROPERTY(Transient, Replicated) TArray my_array;
but when i do DOREPLIFETIME(…classname., my_array)
i get following break, in the code:
RepLayout.cpp
else if ( ArrayNum != CompareArrayNum )
{
// If nothing below us changed, we either shrunk, or we grew and our inner was an array that didn't have any elements
check( ArrayNum < CompareArrayNum || Cmds[CmdIndex + 1].Type == REPCMD_DynamicArray );
:..}
Is it not possbile to replicated Arrays or more specifically Arrays of USTRUCTS?
if I remove the DOREPLIFETIME everything works, ofc it wont replicated :P.
but if i add it,i get the break, because the check(…) doesn’t succeed…:
I think, you should use array of UCLASSes instead of USTRACTs. Use this approach to implement array of UCLASSes Replicating TArrays crashes game - Multiplayer & Networking - Epic Developer Community Forums
Stumbled across this looking for the solution myself, so while I’m late I figure I might as well respond for anyone else finding this page from Google.
To actually replicate USTRUCTS in a TArray (Or anywhere else for that matter) you need to add UPROPERTY() within the struct itself. And that’s all! No need to implement a UCLASS.
Rama’s guide to [UStructs][1] led me to the solution, and it’s worthwhile reading if you’re using UStructs!
[1]: A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums
Of course you must add the UPROPERTY() macro to all struct members that you want to replicate. However, if you have custom members in your struct that UE4 does not know how to serialize, you will probably need to add code to that struct to tell UE4 how to serialize that piece of data to a byte stream. Take a look at this link
here, maybe it will help.