How to create Custom ECollisionChannel in C++

Quite simple, how can I create as many ECollisionChannel as I want through C++ code at runtime for each of my Actors for example?

Can anyone give a code example?

ECollisionChannel is an enum, so you cannot create extra collision channels at runtime with C++. However you can define and use up to 18 extra GameTraceChannels as described here:

Once you have defined your customer GameTraceChannel you can use SetCollisionObjectType to assign it to an actor:

GetStaticMesh(MyActorMesh)->SetCollisionObjectType(ECollisionChannel::ECC_GameTraceChannel1);

To make it easier to use yours you can do:

#define ECC_Test ECollisionChannel::ECC_GameTraceChannel2

And what about creating new ones in the constructor? So before the game begins, create lets say 20 new channels that after will be used? Is that possible? How could this be accomplished?

To my knowledge you cannot modify an enum are runtime in C++. If you really need extra collisions channels you can always add them to the engine source code and recompile it.

BTW, why do you need so many collision channels? Very likely that would also pose a performance challenge.

Well, maybe I’m creating myself a problem where there isn’t… So the the scenario is this: We have 20 Characters, which because of stuff, need to have self collisions deactivated so that its different limbs don’t collide. So in its collision channel has to ignore its own collisions. But we want it to collide to everything else in the scene, including other actors of the same type. This means that each actor that we spawn should have its own channel so that it collides with other actors but not with itself. But we won’t have enough channels to do that ( 20 actors, 18 channels ). See my problem? Or is there an obvious easy solution that I don’t see? Is there a function like : Deactivate selfcollisions withing the actor?