Collision Presets and CCD in C++

Is there a way to set collision presets in C++? Also, how to set CCD to true in C++?

Somewhere in the actor that owns the mesh you want to change collision response to, change it like so:

Mesh->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Block);

1 Like

No, this is not what I asked… I need to changing collision preset for example from “BlockAll” to “OverlapAll”. Off course I can just change every object responses to overlap, but it is too massive. And what if I will make some custom collision response.
I’ll have to change it in every code of the fact that I need.

The channels live on the UPrimitiveComponent and there’s a simple method call to change all of responses:

if (UPrimitiveComponent* PrimitiveComponent = Actor->FindComponentByClass<UPrimitiveComponent>())

There’s a bunch of other methods to set specific channel responses, get the current response, etc.


This thread is the first result I got in Google, so I’ll link the answer I found in another thread:

How Do You Set Custom Collision Presets from Code?


Terzalo’s answer is correct. But I do find it kinda dangerous to hardcode strings in such manner, in case you (or your game designer) changes their name in future. Unreal does pop up a warning when there’s no Collision Profile with the given name, but it is easy to miss (check BodyInstance.cpp for more details).

With that in mind, I wanted to share my solution, in case someone else wants to setup this in a C++ - BP integrated environment:

  1. After creating your custom Collision Profile in Projects settings, create an variable in your header file as such:
	UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, meta=(AllowPrivateAccess="true"))
	FCollisionProfileName CollisionProfile;
  1. Set the variable in your Blueprint’s Class Defaults. The only options available will be the existing Collision Profiles, so there is no way to pick one that does not exist.

  1. Use the SetCollisionProfileName function (called from a UPrimitiveComponent or a child class, such as UBoxComponent or UShpereComponent):
PrimiteComponent->SetCollisionProfileName(CollisionProfile.Name, true);
1 Like