How to get collision/trace channel by name in c++?

I setup a custom collision/trace channel from the project’s collision settings and want to retrieve the corresponding ECollisionChannel value by name in c++. How do I do that?

1 Like

I think you will have to set up your own definition in your local file. Which means you have to know ahead which channel(s) you need (ECC_GameTraceChannel1, ECC_GameTraceChannel2, etc.)
and set up some local variable. You could come up with some way choose at run time if needed I imagine, but you have to set up the names yourself.

Full answer is linked here:

This didn’t answer my question. so I didnt accept it. But I just wanted to let everybody know that I have found a new workflow, which made answering this question obsolete. I am now use the GameSettings class from UE and load the necessary data from there wherever I need it.

Uh this should be marked as the answer. Unreal doesn’t expose the editor defined channel names in C++, so you need to define them manually as such:

203880-da.png

3 Likes

// Find the CollisionChannel that belongs to our custom Profile Name (Preset tab) set inside the Project Settings (Collision tab)
ECollisionChannel CollisionChannel;
FCollisionResponseParams ResponseParams;
FName ProfileName = “MyCustomProfileNameSetInEditorProjectSettings”;

if (UCollisionProfile::GetChannelAndResponseParams(ProfileName, CollisionChannel, ResponseParams))
{
	// If our lookup was successful, we now have a Collision Channel to do stuff with.. :)
}
5 Likes