Trying to get overlap events to work for my wall riding experiment

Hi,

Been trying for a good hour or so to get my overlap detection to work between a wall and a capsule component.
Heres the relevant code:



void AFirstPersonCharacter::OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult){
         if (OtherActor) {
                  UE_LOG(LogTemp, Warning, TEXT("youve done it, the overlap works now??"))
                  if (OtherActor->ActorHasTag(TEXT("RunWall")) && (GetCharacterMovement()->IsFalling() == true)) {
                         JumpCount = 0;
                         FVector ForwardVectorCam = Cam->GetForwardVector();
                         OnWall = true;
                         while ((SpaceHeld == true) && (OnWall == true)) {
                                  GetCharacterMovement()->GravityScale = 0;
                                  GetCharacterMovement()->SetPlaneConstraintNormal(FVector(0.f, 0.f, 1.f));
                                  Player->AddForce(ForwardVectorCam * MomentumMultiplier());

                         }
                   }
           }
}




void AFirstPersonCharacter::BeginPlay()
{
         Super::BeginPlay();
         Player->OnComponentBeginOverlap.AddDynamic(this, &AFirstPersonCharacter::OnOverlapBegin);
         Player->OnComponentEndOverlap.AddDynamic(this, &AFirstPersonCharacter::OnOverlapEnd); //initially these were in the tick function but I read somewhere that they had to be in the               beginplay function.
}

void AFirstPersonCharacter::Tick(float DeltaTime)
{
        Super::Tick(DeltaTime);

        float SpaceHeldTime = GetWorld()->GetFirstPlayerController()->GetInputKeyTimeDown("SpaceBar");
        if (SpaceHeldTime > 0.f) {
               SpaceHeld = true;
        }




void AFirstPersonCharacter::OnOverlapEnd(UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex) {
         OnWall = false;
         GetCharacterMovement()->SetPlaneConstraintNormal(FVector(0.f, 0.f, 0.f));
         GetCharacterMovement()->GravityScale = 1.0f;
}


.h



UFUNCTION()
void OnOverlapBegin(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
UFUNCTION()
void OnOverlapEnd(UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);


The problem is there are no error messages, just no working solution currently. I previously had issues with the AddDynamic part of the OnComponentBeginOverlap part but that was fixed with updating some of the arguments. The walls have their generate overlap events ticked, as does the player.

The logger I placed in the overlap begin function should run as soon as I touch the wall, so it’s definitely not a problem with the rest of the code (not yet anyway!), rather a problem with the detection itself.

Any ideas would be very welcome, thanks.

First of all you should check your collision profiles. Otherwise, I noticed that you call OnComponentBegin/EndOverlap on a variable called Player. What is that variable? It probably should be your colliding component instead, usually the capsule component if you are using the standard Unreal character.

Yeah, sorry for not pointing that one out. Player IS the capsule component, very misleading variable name I know hahaha. As for the collision profiles - do you just mean like allowing overlap events and the drop down field for collision presets? If there’s anything else I should know about that would be great, I’ve only ever tinkered with those 2 so I assumed it would just be one of those, but none seem to fix the issue.

Well, you want your capsule to overlap with a wall it seems. That means both your capsule and the wall must have GenerateOverlapEvents checked and the collision profiles must actually be set to overlap (meaning you must set at least one of your actors to overlap the other). E.g. your wall could have Overlap checked for Pawns. I don’t know your situation but unless you are trying to make a ghost or something overlaps are probably not what you are looking for anyway. Your capsule will have to go through the wall to generate overlaps. Have you still set the collision to blocking?

Ah, you see, I assumed that last point was the case. I was reading some info about implementing wall running and they used overlaps, so I assumed must be the solution. But, hey ho, I’ll give hit events a go instead cause I’m much more familiar with it. Appreciate the help and insight!

I overread that you want to do wallrunning (it’s even in the title lol), if you want to detect walls next to your character overlaps are actually not a bad idea but you can’t use your root capsule collision since that should collide with almost everything in the world. You could add another capsule component that is slightly bigger than your collision component and set that to overlap with WorldStatic (and anything else you want to be able to wallrun on) but let it ignore everything else. Then you still have to solve problems like filtering through the overlaps (e.g. the added capsule would also overlap with the floor, maybe move it up a bit) but you’ll figure it out.

Ah yes, that would be a good idea. Thank you, never thought of doing that!

Sorry to keep being a pain, but do you have any idea of how to access the new capsule you have made in the editor inside code?

There are functions defined in AActor that you can use (e.g. GetComponents, GetComponentsByClass, GetComponentsByTag) but I wouldn’t recommend doing it this way. If you want to use your component in C++ you should also create it in C++. This is the way it is intended and most comfortable to use, C++ provides the base implementation and Blueprint can extend it if desired, there are very little good reasons to go the other direction.

Yeah, I got some sleep and gave it a fresh look this morning. Got it working, turns out it was due to a couple failed attempts that I had made to make a working capsule. I had already attempted the C++ implementation of a capsule but it did not seem to actually take effect when ran. Shuffled around some stuff and it works fine now. Thanks for the help!