Access Collision Presets from C++ API

Hi there,

I was wondering if anyone knew how to acces the Collision Presets from within the C++ API?

Background:
I am enrolled in the "Unreal 5.0 C++ Developer: Learn C++ and Make Video Games " And there is a section called “The Crypt Raider”. As a wrap-up the lecturer challenges us to make our own changes.

What I am trying to do:

I want add an InteractiveComponent to an actor which then sets the required prequisitets for being “Grabbed” or interacted with so that I don’t manually have to go Collision → Collision Presets → Grabber: Block.

What I have tried:

Make an actor component → InteractiveComponent —> GetRootActor -->SetProfile?

UInteractionComponent::UInteractionComponent()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = true;

	//Get root Actor and set its collision presets to block Grabber
	UCollisionProfile* Profile = UCollisionProfile::Get();
	Profile->SetResponse(ECC_Grabber, ECC_Visibility, ECR_Block);
	// /GetOwner()-> SetActorEnableCollision(true);


	// ...
}

But this doens’t work, as there is no SetResponse in the documentation. UE Docs

Does anyone have a clue for me?

Thanks in advance!

It sound like you want to change the collision response of something not modify a preset.

You need to call SetCollisionResponseToChannel on the primitive component you want to block. So assuming that would be the root component.

UPrimitiveComponent* Comp = Cast<UPrimitiveComponent>(GetOwner()->GetRootComponent());
if (Comp)
{
    Comp->SetCollisionResponseToChannel(ECC_Grabber, ECR_Block);
}
1 Like

Thank you @DanM !
You are right indeed, yes, it was collision response. I have posted my final implementation just incase someone else finds this post.

UInteractionComponent::UInteractionComponent()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you don't need them.
	PrimaryComponentTick.bCanEverTick = true;

	UPrimitiveComponent* Comp = Cast<UPrimitiveComponent>(GetOwner()->GetRootComponent());
	if (Comp)
	{
		
		//Comp->SetCollisionResponseToChannel("ECC_GameTraceChannel2", "ECR_Block");
		Comp->SetCollisionEnabled(ECollisionEnabled::QueryAndPhysics);
		Comp->SetCollisionResponseToChannel(ECollisionChannel::ECC_GameTraceChannel2, ECollisionResponse::ECR_Block);
	}
}

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

Privacy & Terms