Toggle ECollisionChannel trace responses on Actor in C++?

Is there a way in C++ to toggle the options (Ignore / Overlap / Block) for Trace Responses on an Actor?

The options I am talking about:
Select Actor, Details window, Physics tab, Collision Presets section and set the collision preset to Custom, you will be able to see the Trace Responses. These are used in LineTraceSingleByChannel().

What I have tried:
• I have tried looking for different commands/components by typing myActor-> and then key words like “trace”, “response”, “collision”, and “physics” but nothing seems to lead me to a component that would allow me to set these Trace Responses to an option. This seems to only be accessible through the editor and blueprints.
• I have read the documentation for ECollisionChannel hoping that it might list a way for the options to be accessed. It does not.
• I have tried to look for forum posts about this issue, but the few I found weren’t helpful.

Why set them at runtime?
For objects spawned through C++ at runtime, I need to be able to set these properties. Because they are only created at runtime, I cannot simply go into the editor to check or uncheck the options.

What is the ultimate goal here?
I was hoping to select NPCs and click clickable objects through a custom trace channel. This would allow only the objects using this channel to be considered in the LineTraceSingleByChannel(). Even though ECC_Visibility covers most cases, there will be cases like a clickable item on the ground being obstructed by grass or plants. The line trace would return the grass instead of the clickable item. This is why having all NPCs and clickable items on a single trace channel would be preferable.

My current work-around:
The trace accepts an FCollisionQueryParams whereby Actors can be added to AddIgnoredActors(). I would effectively add every conceivable Actor to this list, minus the NPCs and clickable items. I would rather not do this because the list would become very large and I would have to manage adding/removing objects as they are created/destroyed. It would be significantly less code to just be able to write myActor->GetCollisionThing->SetTraceChannelOption(ECC_GameTraceChannel1, “block”); in an object’s class.

Any ideas? Thanks.

Edit: I did just discover LineTraceMultiByChannel() to which I could sort through the results with a for loop and could set a tag of “clickable” and check for that, then proceed on with my code. This is another solution and probably the best. I would still like to know if there is a way to set the Trace Channel options though.

Hello @e7t5i_x0z1 ,

Is this piece of code is what you are looking for?

SphereOverlap->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
SphereOverlap->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Overlap);

if it is, then thats the example of usage. For your information, SphereOverlap is a USphereComponent. You can also call it from a staticmesh, skeletalMesh, and many more. How do you call it also the same (Component->SetCollisionResponse…).

That piece of code above is similar to this in BP.
image

I hope this help. just reply if its not the case

Ah, so it’s on a MESH thing. I have been trying to call it on the Actor this entire time because when I select the actor in the Outliner, those options show up (when I could have selected the mesh component specifically, but didn’t). That’s where my assumption went wrong. I guess selecting the actor shows all the properties for every component attached? Or perhaps just the root object.

Another thing is that the docs show its inheritance being things related to the engine, not like it’s something that stems from Actor or UObject or anything. So I never would have guessed that it should have been called upon something with a mesh.

Next time, if I see a property on an actor, I will try to call commands from a reference to one of the components the actor has.

You are brilliant, ImAGoodSpoon1! Thank you!

It’s not like blueprint where everything will show up on the list of function. In C++, the intellisense (the list of function/variables) shown is not all and just the one related. For example if you call it from the actor, you can only see the actor related function/variable (also from the parent class). There are many function that should be accessed/called via the object itself and one of them is SetCollisionResponse… But in my opinion, that is a good thing from C++ since we don’t see many unused function and only show us the related one (I usually get confused by the many list of blueprint callable function). I hope my explanation make sense to you.

Edit:
also one more thing, to make it easier, you can just look on the BP first. Example if you want to set the collision, you should click the mesh first right before that options showed for you. Then in C++, you can only do that by calling it from the mesh.

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