Download

Collision

Hello, everyone, I will like to know how to reference Components in blueprint in c++. I am trying to use capsule collision component(parent to the Skeleton mesh) to test if the character hit something(wall jumping). Do I need to create a new class(Actor component), if so, I can’t parent it to my character? What should I do? Thank you for your time.

You can’t get components that you added to a Blueprint Asset in C++. Well, actually you can - but it’s not a good workflow or design.

The best approach is to make a new C++ class and add your extra component there, that way you know it’s always valid and you can access it. This may not be neccesary however, as you may be able to use the Capsule Collision that is already part of the Character class for your collision tests (unless you need to check against different collision channels).

I do it all the time…



ACockpitGravityPawn::ACockpitGravityPawn(const FObjectInitializer& ObjectInitializer) :
	Super(ObjectInitializer)
{
	PrimaryActorTick.bCanEverTick = true;

	CollisionComponent = CreateDefaultSubobject<UCapsuleComponent>(ADefaultPawn::CollisionComponentName);
	CollisionComponent->InitCapsuleSize(45.0, FMath::Max(COCKPIT_GRAVITY_OFFSET, 45.0f));
	CollisionComponent->SetCollisionProfileName(UCollisionProfile::Pawn_ProfileName);
	CollisionComponent->CanCharacterStepUpOn = ECB_No;
	CollisionComponent->bShouldUpdatePhysicsVolume = true;
	CollisionComponent->SetCanEverAffectNavigation(false);
	CollisionComponent->bDynamicObstacle = true;
	CollisionComponent->SetEnableGravity(false);
	RootComponent = CollisionComponent;
	_selfDestruct = false;
...
...

Thank you Jamsh, I wanted to check if capsule collides with a wall, I am trying to achieve wall jump. I am not sure how to reference capsule in my code. My idea was to create actor component, however, you can’t parent it to skeleton mesh component. Should I create a new actor?

Funkinessfactor, Thank you, are u creating another collision component?, if so, How would parent it to the mesh via code. I ama using the third person template. Do you mind explain RootComponent, I am still confused what that is. Thank you.

Thanks, TheJamsh, will I add a new actor or actor component class? How would I attach it to skeleton mesh? I tried a creating new actor component class I was able to parent it in my Blueprint. Any advice? I want to make sure that the capsule collision compone t follows the skeleton mesh component.

Making child actor right way? Drag the actor and parent it via Blueprint? Then create capsule via code?

Just add this in the constructor where you create the additional capsule component:



MyExtraCapsuleComponent->SetupAttachment(GetMesh(), NAME_None);


Mine work then doesn’t work while using that whats the deal?

I see, if you are doing line trace, wouldn’t need a reference to your capsule collision?

No idea, need more info than that.

I’m not sure what you mean?

I figured it out and was become lost in a mix. I forgot use const. Also Sometimes I must reset the editor for the change to show up. None the less problem solved.