Using the C++ third person starter project, I’m trying to add a large USphereComponent to the main character to receive overlap messages when the character gets close to some objects.
At the same time I want the capsule collider to collide and stop the character walking through the same object, but I can’t get both to work at the same time.
I can either have collision stopping the character walking through the object or get the overlap message from the larger sphere collide, but I can’t get both to act like I want at the same time.
Using the C++ third person starter project I already had the capsule collider, so I added the USphereComponent in code;
.h file;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Character)
class USphereComponent* SphereCollider;
and in the cpp file;
SphereCollider = CreateDefaultSubobject<USphereComponent>(TEXT("MySphereCollider"));
SphereCollider->SetupAttachment(GetRootComponent());
In the project settings I added a new collision channel simply called “TestChannel” and set the new sphere collider’s object type to TestChannel.
I then added a cube to the level and set it’s collision to custom and it to block everything except the TestChannel which is set to Overlap.
Back in the c++ file I added ;
SphereCollider->OnComponentBeginOverlap.AddDynamic(this, &ATest_CollisionCharacter::SphereBeginOverlap);
to the BeginPlay()
SphereCollider->OnComponentBeginOverlap.AddDynamic(this, &ATest_CollisionCharacter::SphereBeginOverlap);
I simply set the SphereBeginOverlap function to output the text “Sphere Collided”.
I also set the radius of he sphere collider to about twice the size of the character so it would collide before the character got too close.
This doesn’t generate any overlaps, but if I add a extra Box Trigger inside the cube I can get the overlap to work and the original cube also collides with the capsule stopping the character walking through it.
As a last resort this will work, but I have custom modeled collision objects in my game that will make this messy.
Did I set something up wrong or is it not possible to get different collisions on child colliders to the main capsule collider?