Would it be possible to expose TMap to reflection system and by extension to replication ?
I have run my self in cases where I’d really like to have some sort of ordered list, where order of data is important and should be maintained. One of that case is mapping input to action bar and/or inventory where I really need to maintain certain order of items.
I have hacked solution around by using Struct with ID variable, but it’s not efficient, since something like TArray can be only be really searched linearly, and by that can’t be really used for bigger amounts of data and still be efficient.
For my GameState, I’d like to create a dictionary/map where the teams are the keys and values are the scores. TMap replication would be great for this, because now I have resort to a not-so-nice alternative.
Could we get at least information, if that’s possible/planned or just not wort time working on exposing it back to reflection/editor ?
I just found another use case where using TMap would be benficial. In UDataAsset for storing information about items, where they could be fast searched.
Currently I use TArray, but you can imagine that linear search with more than 100 items might start to be problematic when there need to be performed several of such searches at once.
Please add blueprint/network support for all important container types. Arrays are nice and all but… it’s arrays, and they are very limited.
I really figured this would have been a higher priority for epic since container types are fundamental and their use-cases are enormous.
:
I do recall reading somewhere on answerhub that it can be implemented in custom source and has been by some users but I have yet to find any source showing the implementation. After checking the source it looks like to implement TMap for BP and replication you need to add support for UE4’s serialization and reflection yourself and the replication part should be a snap. It’s the first parts that seem daunting. I wish I could do it myself but my c++ is very limited as the bulk of my experience is in managed languages (c# mainly).
Just a quick update to let you know that this feature is being worked on and we’re hoping to have something in a near-future release.
There have repeated demands and several attempts over the years to address this; it’s certainly not a ‘snap’. The first iteration will likely just involve basic serialisation and reflection, with deeper editor and BP support coming later.
Sorry to bump such an old thread but is there any update on this? Being able to serialize maps so they can be used in the editor would be a serious plus.
Well, the source said it was deprecated, though the docs don’t reflect that. This was on 4.10.1. Did I set something up incorrectly to cause it to go down that codepath or is there an issue there?
It also appeared that I can’t use UStructs as keys to TMaps if I want them to replicate. This gave compiler errors saying it’s unsupported.
UStructs can’t be used as map keys if the map is declared as a UPROPERTY.
As for the other issue @skyphyr, did you find anything out? I just ran into this myself. I can only guess that TMap replication is still unsupported. Or has anyone else managed to get it working somehow?
Was just sumbling over that part in the post…
What about the FindByPredicate() method ? Does this also just do a linear search internally?
I somehow thought that it would be more efficient than a loop…
There are better ways. It’s not exactly efficient to replicate them anyway. TMaps work fine, they just don’t support replication (like the vast majority of other UE containers and types).
Has anyone actually tested this before bleating on about it’s lack of support? I know maps that are created by BP don’t support it, but if you create them in C++ and provide a NetSerialize function for your custom USTRUCT, it may work.
I don’t understand why it’s so difficult to replicate a TMap, what are the programming challenges involved? Any situation I can think of has an obvious solution.