Float precision with vector key maps
I'm wondering if using a vector as a key type for maps is stable. I know the engine likes to add (or subtract) a non-zero but negligible amount to vectors at least with viewport transformations I.e. +0.0000002 First I'm curious why it does that, but more importantly is a map key checking exactly equal or nearly equal? If nearly to what decimal? I haven't had time to test these myself.
asked Mar 20 '17 at 12:18 PM in Using UE4
It won't work very well because of floating point errors. There is a limit to how accurate a number can be represented. So if you are using GetActorLocation etc. it's not going to be reliable/precise enough to work in a map. Even explicitly setting a value probably won't always work.
In C++ you could probably write your own check so it uses nearly equal instead of ==. I'm not sure if that is possible in Unreal, or if it would even be a good thing to do.
An Int vector would work better, if that fits what you want to do. If you are dealing with actors in 3D space that are aligned to a grid, you could store their rounded locations as Int vectors as a variable, and use that in the map. Depends on what you are trying to do.
answered Mar 20 '17 at 12:42 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here