Dictionary Map Issue: overwriting data.

Hello ev! I’ve been working on optimizing my map generator for days now, using other bp and event dispatchers to avoid it taking too much work on its own. The logic is: while the generator validates the rooms and spawns them, it takes the tag and the name of the room in case it is valid and transmits them in call to a bp manager. The purpose of the bp manager is to collect all the data related to the rooms actually spawned and to sort them using a Dictionary Map, so that then the bp “interior spawner”, once the generation is completed, can easily access each single room by tag, and consequently take different actions for each one. And here comes my problem. The code I wrote to manipulate the map dictionary, works in print string before the data enters the map. But then, after the first iteration, the data of the rooms is overwritten instead of being accumulated and updated. I tried several times to structure the code in different ways, but I always have this result. The keys are all correct but not the values ​​related to each of them. Can someone more knowledgeable than me in dictionary map help me? Sorry for the text, I tried to be as brief as possible. Thank you very much!


1 Like

You can’t order maps.

Also nice to know, is you don’t have to check if something is in a map before adding it. Just say ‘ADD’ and you’re done. The ADD call adds the key if not there, or updates it if it is.

So to answer your question, possibly, you can’t add a key more than once.

1 Like

Thanks for replying! @ClockworkOcean

I know keys are unique, infact I want to update values for each key. I tried using add in both cases and it still overwrote instead of adding the values ​​for existing tags.

1 Like

This is what I’m saying, ADD will overwrite what’s there with the new information.

1 Like

So I can’t get a total and updated sum in real time? I was using the contain with branch just to avoid an overwrite in case the key was already present, what I wanted to do in this case was to take the value/values ​​already associated with the existing key and add them. @ClockworkOcean

1 Like

Ah…

If you have a map

Name:Static mesh component

The only things you can do are

  1. Add ‘name’ and SMC reference

  2. Change the SMC that goes with ‘name’

  3. Remove the mapping.

1 Like

so i lost 4 days of work! BUT that’s AWESOME! :smiley:

1 Like

If you want to have more than one SMC with each name, all is not lost

Make your map as

name:Array of static mesh component reference

:slight_smile:

1 Like

the funny thing is that I was going crazy building this part to avoid what I built before, that is branches and new arrays with component has tag , all to be managed manually. Because in the future I will surely add new rooms.

1 Like

What sort of data are you trying to store?

Name is the name of the room and SMC is a mesh.

1 Like

probably it’s tiredness, but what do you mean by “name” “array”? Because when in the detail panel I set map on the first parameter if I’m not mistaken I can’t make further settings on the key and value parameters. I’m a bit confused, forgive me. @ClockworkOcean

At the moment I have 5 rooms different from each other in shape and size, to identify them, for each of them I have manually assigned a tag to be able to identify them. My goal is to have a 100% generated map, to have lists that by tag, tell me how many rooms are spawned effectively and validly. So that for each of them, the bp interior takes position and socket to spawn the meshes inside the room. @ClockworkOcean

1 Like

If you make a struct like this

Then you can make a map like this

So each name can refer to many static mesh components

But maybe that’s not what you mean… I don’t think I get your system.

If you’re spawning a room blueprint, then surely you want to collect actor references?

1 Like

If it doesn’t bother you too much, if you could explain this point better it could be the crucial turning point. Because my values ​​are of the scene component type because the static mesh comp are in turn contained in a sc that acts as a folder. I had a doubt whether this type of value was cumulative or not. Anyway, really thank you! @ClockworkOcean

1 Like

The problem is that the room bp are children of a single room bp. So I had to change the static mesh in the child bp as child components. It might cause problems using actor to reference them. @ClockworkOcean

You would probably want a struct to hold room information in the map. If you do key => value as name => static mesh, then you can only hold 1 mesh per room. I’m guessing you want a room to hold multiple meshes.

Unfortunately unreal doesn’t seem to expose modifying map values via reference for specific sub elements so you are probably going to have to make a temp var of the struct during manipulation and then add it back to the map at the set key => in turn replacing the value.

image

1 Like

So if I understand correctly I have to create both a map and an array type struct? @3dRaven

Yes the map would contain a key => name or string and value of type struct that would hold all of the information describing a room.

1 Like

Ok I’ll try to build the code, I’ll let you know the outcome if you want. Thank you so much! Remember that the world needs people like you. Always. @ClockworkOcean @3dRaven

2 Likes

@ClockworkOcean @3dRaven ok guys, I’m a bit closer than the beginning but something is still missing. I missunderstood something for sure, anyway I share with you what I’ve got. I did a structure blueprint with 2 parameters : RoomName as Scene Component Object ref array and the second one as integer to count the each room for tag. Then I referenced this structure in bp manager and used this structure as second parameter in dictionary map, first one is tag name. Now, the problem is that the rooms are shown separately one by one, even if they share the tag, and the integer counter is not binding to the type of room it should count. That is, instead of counting every time a same room is added to the structure, it simply counts + 1 for every room added. I’m exploding.