To start this really annoyed me I couldn’t pass back by ref from a function but ill talk about that in the end for now the problem is I have a map with the key being a string and the value being a struct with an array in it. I pass the map into a function by-ref because i’m choosing between 3 different maps using an integer. In the function if the struct doesn’t exist in the map I make a new one and add my actor to its array all good at this point. However if the struct does exist in the map I brake it and I should just be able to add to the array and be done with it. When I brake the struct it says by-ref but it wont change when I add to the array. The only work around I could come up with is very inefficient I have to copy the array into a temp array then add the actor to that and remake the struct. After that I have to add the new struct back to the map overwriting the old one. I really don’t like this method because if I have 100 actors or so in the array every time I want to add or remove one I have to remake the whole thing. I am looking for a better work around but honestly I am wondering why just adding to the array after braking the struct didn’t work in the first place.
On a last note the pass back by-ref from a function would have been really helpful when choosing the map I wanted to use. As that wasn’t an option I had to choose the map before I sent it into the function. I would have much rather of gotten the map I wanted to use before I did the rest of it but what ever.
Anywho thank you for any help in advance this isn’t impeding my work but I just cant wrap my head around why it isn’t working the other way. I was also wondering if maybe someone could shed some light on this or had a better work around for me before I screw with trying to make it more efficient.
However if the struct does exist in
the map I brake it and I should just
be able to add to the array and be
done with it. When I brake the struct
it says by-ref but it wont change when
I add to the array.
Hm, how can you even have a map with no struct? Or do you just mean default values?
default values of the map is empty as you can see in the image I use the find node to get the struct if it exists in the map. Then I brake it if it finds it and when I hover over the node it says that its by-ref then I figure I should just be able to pull off of the array in the struct and use an add node to add the connector actor but when I do that it never updates the struct. Even if I were to set members in struct after I add to it nothing changes and im not sure why if its by-ref.
ok im not sure if you looked at the images I added to the post but im not using set members in struct because it didn’t work. The struct is not in an array its a value in a map the array is in the struct. I want to update the struct after I add or remove the actor from its array. However even though when I brake the struct it says its by-ref changing its array in anyway doesn’t update the struct even when I set members in struct it wont permanently update it. The last image show cases how I had to work around that but its very inefficient. I am trying to figure out why manipulating the array in the struct doesn’t update it. Also if maybe there is a better work around if this is just a bug or something
I know for a fact that you can’t pass a struct by-ref via an Event, can’t recall if that’s true for functions, too. I don’t think you can, they’re not Uobjects.
well I tried a different method I made a local variable to hold the struct when I get it from the find I then take and break it use an add node to add the connector to the array and add the local variable into the map
ah ok the way you worded it confused me yes I have tried that this is inside of a function I pass the map in by-ref find the struct in it if it exists I brake it and see if it contains the actor I want to add/remove. In this case if it doesn’t contain it I have tried off the false taking the array from the struct and adding the actor to it using the add node. That didn’t work then I tried after the add node doing the set members in struct and that also didn’t work. The only outcome is all the actors I had in the array disappear and all im left with is the last actor to call this.
Im am still confused as to why the local variable is needed why I couldn’t just brake the struct off the find node edit it then re-add it back into the map from there its supposed to be by-ref right but what ever this worked