I’ve got a bunch of items and they have sphere Triggers on them. When the player overlaps with the sphere the item highlights. However, I’m thinking having a lot of items in a scene running sphere triggers is probably not optimal. So, looking for some advice on the most optimal way to do it?
Some alternative options I can think of…
Have the sphere trigger on the player, not the items, so it’s only one object checking for the overlaps not many of them.
Have the player run a sphere overlap a few times a second (I don’t need it ticking every frame).
I here that the most performant option is often to get the squared distance from the objects, but I’m not sure how I’d do that without an overlap sphere to identify them first??
Thanks, yeah I’m thinking it’s one of the two options.
Although now I think about it, overlap triggers get a single actor, not an array of all actors so I think my option #2 is likely better.
So, I’m thinking the best method here might be to run an overlap sphere maybe 3 times a second and collect all actors that it collides with (as they will have a specific collision setting to filter them).
It seems you are pre-optimizing. You can be sure that attaching functions to events such as OnOverlapBegin and OnOverlapEnd (something along those lines), will be the most performant option there is.
Your fear of getting only one object per event is wrong as your callback will get called per every object overlapped. So if you want to keep an array of objects within the given distance then all you need is to push on Begin and remove on End.
Avoid ticks, avoid timers. These are not things you want to be inconsistent.
Performance wise you can make custom channel reserved just for this.
Yeah, they just highlight and I add them to an array. Don’t need the closest or anything, just all within a distance of the player so I can highlight them.
Here’s what I’m currently thinking (from the player BP)…