best way to make a map of array / list

hi

what best describes what i want to make is a map where the value (not key) part can be a list or array as opposed to a single value

at this point i am making use of a structure with the elements of the structure as array variables

so i dereference the strucutre to get an array and then dereference the array

is there a better way to do this?

thanks

1 Like

You could do it like this

where MyStruct is

It sounds like this is what you’re doing, I don’t think there is a better way…

You can also have a tinker with a structure which is a map of ( key and another structure ). It’s just one thing, but slightly less intuitive to use

PS: If you’re going to use this sort of thing in the save game, I would do some tests first, to make sure it serializes correctly ( gets mapped into the save game and back ).

Another way to do this, is to just have an array, and compute your offset into it using a bit of math.

1 Like

According to my knowledge structure wrapper is the only way to do it (as showed by the ClockworkOcean). TMaps don’t support values as arrays - even in cpp it’s not supported.

The other way would be to use std::map and this can have almost any type as value, but it’s also rather not recommended to mix standard types with Unreal ones (and it will not be supported in BP).

2 Likes

For the record, this is technically incorrect. You can have whatever type you like as the ValueType of a TMap.
The reflection system does not support it, so it can not be a UPROPERTY, but there is no limitation in TMap.

	TMap<int, TArray<FVector>> MapOfArrays_Ok;
	UPROPERTY() TMap<int, TArray<FVector>> MapOfArrays_Error;
3 Likes

You are right, I didn’t test it without UPROPERTY. Thanks for pointing this out :slight_smile:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.