Least expensive way to check each element of an struct array in tick?

I’m working on a VR Gesture system. Ideally, this system regularly updates (probably won’t be in event tick, but rather fixed tick rate), and decides which struct out of an array of structs is the best choice.

I can’t imagine this not requiring a for loop, and I know in a majority of cases that using for loops in updates from blueprints is generally a bad idea. So I’m also wondering if doing it via a c++ function is viable with the amount of data being accessed.

Each struct roughly contains 4-6 3D vectors, floats, and booleans.

There may be anywhere from 5 to 70 of these structs to access at once for all I know. It’s intended to be usable in a multitude of projects.

Any thoughts, or even alternative solutions, would be greatly appreciated.

The words least-expensive, array and tick don’t go together :slight_smile:

How do you know which is the best?

I was thinking something simple like a tolerance value to compare. At least for most of the 3d vector values, since the two main values will simply be location and rotation (although now that I think about it, rotation will likely be rotator. Used to them being vector3’s from unity)

Then beyond that, just the closest value to the one changing in runtime

But I may yet include both velocity and angular velocity, which may change how I’ll want it to decide

1 Like

I’m thinking of something like the ‘hash’ that dictionary ( map ) data types use.

If you could implement something like that ( probably in CPP ), then you could do it every tick, because you would be able to jump straight to the relevant entry… :slight_smile:

1 Like

I was hoping there was something like that, but wasn’t sure what it would be called.

I’ll definitely be looking into it, thanks a ton for the help

1 Like

If you’re looking up exact values, then you could do it in BP. But if you want to be approximate, the CPP would be better. You could write your own hash :slight_smile:

Apologies for the long and wordy post, but I did a bit of reading on hashes and maps and was wondering if I could get a second opinion on a choosing which routes to explore
I’ve found a few options that may do what I want, but I’m definitely open to alternatives as well.

From what I’ve read, the main methods that I would think are my best options are:

Spatial hashing, which from my understanding, is a fixed grid in 3d space that is indexed, then each position within that grid space is stored in the array at said index

quadtrees (or octrees in 3d space?), which from what I’ve read are significantly more complicated to work with and possibly less performant (that part wasn’t entirely clear, but I’m gonna lean towards it being true, because my implementation probably will be).
It kind of sounds like spatial hash maps being nested inside of each other, but I didn’t read that far into it so I’m not exactly sure.

I also thought of a hash map that maps each base 10 digit onto its own array (probably from like 0.01m to 10m, since that’s likely all that’s needed) and mapping each 0-9 value to its own index position. Only thing is I’d have to do this for each axis in a vector, then for multiple vectors (although probably only 4-6 of them. But that of course means 12-18 iterations). But then I’d also need to retrieve base 10 digit values for at least 2 of these vectors consistently during runtime
Although now that i think about it, this kind of just sounds like quadtreeing, but each grid has 10x10x10 within it, and I’m just checking each axis individually

I’m not sure if any of these are what you had in mind, so if you had a better idea I’d love to hear it.
I figure if it comes to it, I’ll just make functions for all of these and test their performance impact

1 Like

It sounds like you’re on top of the research.

You could do it in stages.

If you do a very efficient short circuit algorithm in blueprint, that might actually work. You can’t leave anything to chance, just explicitly take the quickest route through the calculations, and see where there that gets you.

If the number of operations ( for any of these methods ) is of the order < 100 ( plucked from the air ), you’ll probably be ok. Give it a go.

If it’s too slow, the either change approach, or move to C++.

Does that makes sense?