If I am correct you can’t do this? As the type has to have a constructor and == operator etc.
I’m basically looking for confirmation that this can’t be done because I am just getting a massive error which basically says: Needs constructor for Seed Data
or if it can be done please let me know how.
Personally, when it comes to 2D arrays (and extended to 2D maps), I prefer to just wrap them in a struct and make a simple accessor / setter function. Depending on your performance needs it can save a lot of headaches for just one extra instruction.
Also, again depending on performance concerns, TArrays can use find and are usable as UPROPERTY’s, so unless you are accessing multiple times per tick or you data is huge it can sometimes be the more sensible choice.
I don’t know if it’s impossible, but it’s probably best to avoid it to be honest. I know you can’t have nested containers as UPROPERTY()'s, so you have to manage your objects yourself which can be a pain. Same goes with 2D TArrays.
I notice you’re using C++'s default ‘int’ as the type, You really want to stick to Unreal integer types, especially when using it’s containers.
Think of the TMap as a list of objects which are indexed by a hash value.
A TMap is an object as well, so you can have a hash set of hash sets.
Keep in mind that the TMap is not supported by the editor itself, so you can’t directly expose it to end users via the UPROPERTY() macro. If you want to expose access to a TMap, you’d have to create functions which act as accessors to your internal data structure. Likewise with nested TArray’s: TArray<TArray<int32>> MyArray;
Pro tip: Try to keep your key value an integer value. It’s much faster to do integer comparisons than string comparisons. If you want something human readable, using enums for keys works perfectly.
For those who wish to have something that can be accessed by blueprints or for some reason were unable to compile a 2D Map when trying to save it as a UPROPERTY for save games (like in my case for 5.4), use a struct.
Helps with blueprints or with being able to serialize the data. Not sure if you actually can serialize a 2D map directly as that’s why I got compile errors in VS, but this is still the only way you’ll get it to work with blueprints .