From my understanding it isn’t possible to get the multi sphere trace to register only one hit for each unique enemy (more than 10 trace hits appear for each enemy), so I’ve built this system out. However, I am a beginner with coding and I’m sure my logic is deeply flawed in some way, and I have no idea how to fix it. Deeply appreiciate any assistance!
each component counts as a hit. so each actor has multiple hits
all you need is AddUnique though, you dont need to check if it contains or remove on loop.
or you could make a custom trace/object channel that only hits the desired component
Thank you for the reply, but I think there’s more happening under the surface. Here’s some more information.
The enemies I’m tracing for only have 4 or 5 components in their blueprints, but the trace hits are returning over 20 hits for some enemy types.
The remove on loop was a fix to prevent errors due to the sphere trace trying to interact with enemy instances that were already hit/removed and were no longer valid. (Array would keep references to all of the actors that have already been hit, and processed all of the destroyed enemies every time there was a new hit).
The implementation I attached actually works for processing some of the enemy types one time, but for enemies which have a bigger health pool the amount of times they are hit is completely unreliable and seemingly dependant on how many other enemies are being hit at the same time. Not sure if it’s relevant, but both enemy types are also children of the same BP_enemy blueprint.
i think each physics asset counts too, so 1 mesh would have many hits.
you can just printstring the hit components to see what youre hitting exactly.
- Adjust Collision Settings: Configure the collision settings so that only specific components are detectable by the trace. For instance, set the mesh components to “NoCollision” and ensure that only the capsule component has the desired collision settings. This method reduces redundant hits by limiting the trace to essential components.
Epic Developer Community Forums
- Filter Unique Actors: After performing the trace, iterate through the hit results and add each actor to an array using the
AddUnique
function. This ensures that each actor is processed only once, even if multiple components were hit.
Epic Developer Community Forums
- Create Custom Collision Channels: Define a new object channel in the project settings and assign it exclusively to the primary component of your actors (e.g., the capsule component). Then, perform the trace against this custom channel, which helps in detecting only the intended components and avoids multiple hits from the same actor
Thank you for looking into it with AI, but I was hoping the forums would be a place to talk to people with similar experiences. AI is often helpful but the nuance here made me want to hear directly from people with lived expeience.
Oh I see! I think I’ve been misunderstanding collision channels in Unreal until now. Is it usually common practice to ignore all collision on all character components except for the collision capsule?
The traces are now registering as one dot, but the hit still doesnt fire if it is a singular actor, and is instead only hit if there are 2 of the same actor in the radius, and damaged according to how many are hit by the same sphere trace by channel. I’m guessing this is related to my scuffed code loop?
Here’s a slightly newer setup. I haven’t removed the checks like you had suggested before because hits were no longer being registered at all
Nothing hurts quite like a practiced programmer hitting you with elipsis haha
This works! The final tweak required was to clear the array immediately before every trace, as the previous hits are otherwise stored permanently and will error out if the hit actors are being destroyed. Thank you for the help!
nothing wrong with that approach but you can also just encapsulate in a function and use a LocalVariable.