0
votes

Can I use std::vector, std::unordered_map instead of TMap, TVector...etc?.

I need a class to serialize all it's info, and I have code that already works with stl.

I tested trying to use UPROPERTY on them and it's not possible,(Any way to do that?). But I'm ok with that.

What I need to know is what happens when serializing the whole class when some of it's members are stl containers.

1

1 Answers

1
votes

You should not use them.

You should not use standard C++ library for other then communicating with external libraries and if you use them you should avoid using UFUNCTION and UPROPERTY on them. https://answers.unrealengine.com/questions/180421/how-to-use-c-standard-library-std.html

If you need to serialize properties, I'd like to propose using Rama's system (UE Wiki). I used it in my game to save/load data to binary files, but it could be easily extended to send data over network.

Basically, in that system you are overloading << operator. Pros is that you define all structure in one place and one function could be used both for saving and for loading. Note that I've encountered compilation problems when I tried to compile code like:

TArray<UObject> array = // init

// ar is container to serialization
ar << array;

But I solved it by mapping UObjects to UStructs so code like

TArray<FStruct> array = // init

// as is container to serialization
ar << array;     // now, this will compile

It was in UE 4.15 and it is possible that it was solved in later versions.

If you want to examine my implementation of Rama's system system more, you can look at my repo of my game TCF2 (GitHub). You are looking for a /Source/GameSave/[Public|Private]/SaveGameCarrier - this is my main class for saving. Example of mapping helper could be find in /Source/Inventory/Public/InventoryHelpers.h