Custom trace channel in c++?

I created a custom trace channel from the collision tab in project settings.
It may sound stupid but I have no idea how to use my new channel in c++: for example I want to do a single trace using my custom channel, how can I do it? (I mean, when it comes to specify the ECollisionChannel parameter)

They show up as ECC_GameTraceChannel1, ECC_GameTraceChannel2, etc. in C++. If you look in the EngineTypes.h file you can see this bit here, which tells you probably the best way to deal with it.

	// in order to use this custom channels
	// we recommend to define in your local file
	// - i.e. #define COLLISION_WEAPON		ECC_GameTraceChannel1
	// and make sure you customize these it in INI file by
	// 
	// in DefaultEngine.ini
	//
	// [/Script/Engine.CollisionProfile]
	// GameTraceChannel1="Weapon"
	// 
	// also in the INI file, you can override collision profiles that are defined by simply redefining
	// note that Weapon isn't defined in the BaseEngine.ini file, but "Trigger" is defined in Engine
	// +Profiles=(Name="Trigger",CollisionEnabled=QueryOnly,ObjectTypeName=WorldDynamic, DefaultResponse=ECR_Overlap, CustomResponses=((Channel=Visibility, Response=ECR_Ignore), (Channel=Weapon, Response=ECR_Ignore)))
7 Likes

UE4 ver 4.17.2

See DefaultEngine.ini in your Project. You will found what you named TraceChannel rows, likes below:
(If you made new TraceChanel “Tracer01”, Search “Tracer01” in DefaultEngine.ini.)

DefaultChannelResponses=(Channel=ECC_GameTraceChannel2,Name="Tracer01",DefaultResponse=ECR_Block,bTraceType=True,bStaticObject=False)

ECC_GameTraceChannel2 is “enum ECollisionChannel”. You have to change it to ETraceQueryType. Use UEngineTypes::ConvertToTraceType() for convert to ETraceQueryType from ECollisionChannel likes below:

ETraceQueryType MyTraceType = UEngineTypes::ConvertToTraceType(ECollisionChannel::ECC_GameTraceChannel2);

Then You should use MyTraceType to Trace Function( Ex: SphereTraceMulti() )

9 Likes

ETraceQueryType - 4.22: no such variable type :frowning:

It is ETraceTypeQuery

In what file should you add:
ETraceQueryType MyTraceType = UEngineTypes::ConvertToTraceType(ECollisionChannel::ECC_GameTraceChannel2);

In your project header file or just where you plan to use this?

1 Like

Thanks 4 this!