Using vector as key in map is leading to trouble and I think it's the vector's float-based nature

I have an actor when added to the game gets stored into a map with the actors attributes being stored as the map’s values and the actor’s spawn location as the key. This is so later when the player saves the game the contents of the map can be stored in the save game ref and later loaded.

The problem I’m having is that when the actor is relocated, I search the map for a vector that exists in the same spot that the actor was first located so that I may remove it and put in an updated entry, and while these vectors are shown as identical in a print string’s output, the vector is not found in the map. I have found that if I round the values of the xyz coordinates it does work, but I’m worried that’s not a great solution.

I’m considering overhauling the whole save system for these actors so that the key is not a vector because I don’t know if I my rounding procedure is going to work 100% of the time.

More information: the vector searched for is the location of the platform the actor is standing on, plus 5 to the z axis to account for it’s width. As I said, the vector that is in the map and the vector I search for are shown as identical when I use the print string function but if I do ‘is equal’ it returns false.

1 Like

I’ve had exactly the same thing. I did things a totally different way in the end. But you can replace the vector with a custom struct which is a group of 3 ints :slight_smile:

Well on the plus side I know more about the UE then I did when I started this project so maybe I’ll be able to figure something out. I think it’s going to involve giving each of the involved actors an ID on spawn.

Thanks.

1 Like

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