Announcement

Collapse
No announcement yet.

OnComponentBeginOverlap not firing

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    OnComponentBeginOverlap not firing

    For some reason, I can not get the binded function to fire.
    Here is the relevent code

    Header File
    Code:
    // Fill out your copyright notice in the Description page of Project Settings.
    #pragma once
    #include "CoreMinimal.h"
    #include "GameFramework/Pawn.h"
    #include "PPlayerPlane.generated.h"
    UCLASS()
    class MYPROJECT_API APlayerPlane : public APawn
    {
        GENERATED_BODY()
    public:
        // Sets default values for this pawn's properties
        APlayerPlane();
        UPROPERTY(EditAnywhere, Category = "Components")
        class UStaticMeshComponent* PlayerPlaneModel;
    protected:
        // Called when the game starts or when spawned
        virtual void BeginPlay() override;
    public: 
        // Called every frame
        virtual void Tick(float DeltaTime) override;
        UFUNCTION()
        void OnOverlap( 
            UPrimitiveComponent* OverlappedComp, 
            AActor* OtherActor, 
            UPrimitiveComponent* OtherComp, 
            int32 OtherBodyIndex,
            bool bFromSweep, 
            const FHitResult& SweepResult 
        );
    };
    and the cpp file

    Code:
    APlayerPlane::APlayerPlane()
    {
        // Set this pawn to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
        PrimaryActorTick.bCanEverTick = true;
    
        PlayerPlaneModel = CreateDefaultSubobject<UStaticMeshComponent>("Base Plane Model");
        SetRootComponent( PlayerPlaneModel ); 
    }
    // Called when the game starts or when spawned
    void APlayerPlane::BeginPlay()
    {
        Super::BeginPlay();
        if ( !IsPendingKill() )
        {
            DirtyUtility :: Log( "About to bind function" );
            PlayerPlaneModel -> OnComponentBeginOverlap.AddDynamic( this, &APlayerPlane :: OnOverlap );
        }
    }
    void APlayerPlane :: OnOverlap (
        UPrimitiveComponent* OverlappedComp, 
        AActor* OtherActor, 
        UPrimitiveComponent* OtherComp, 
        int32 OtherBodyIndex, 
        bool bFromSweep, 
        const FHitResult& SweepResult )
    {
        DirtyUtility :: Log( "This has overlaped" );
    }
    Note that DirtyUtility :: Log is my own logging function.

    I have made sure that all actors have generate overlapping events enabled
    I have made sure that the function is marked as a UFUNCTION
    I have made sure that the function is binded in begin play instead of the constructer.
    I also make sure the object is marked for kill

    When I run the game after compiling, the log does complain that function may not be a UFUNCTION or that the object is pending kill

    And when the test cube I have setup for the actor overlaps with another object, nothing happens

    #2
    I never used OnOverlap, checking the API, i'm not sure you could use it like you did, as it's marked as UPROPERTY...
    Try using OnOverlapBegin, and OnOverlapEnd
    GitHub Repo - WIP RPG

    Comment


      #3
      You need to setup your CollisionProfile otherwise it will not work.

      Comment


        #4
        Originally posted by silik1 View Post
        I never used OnOverlap, checking the API, i'm not sure you could use it like you did, as it's marked as UPROPERTY...
        Try using OnOverlapBegin, and OnOverlapEnd
        I'm not using the OnOverlapBegin of the actor. I'm trying to bind a function to the model's overlap begin event.
        Originally posted by Lambdarevolution View Post
        You need to setup your CollisionProfile otherwise it will not work.
        I have, I have tested the same actors with blueprints the OnComponentOverlapBegin fires, but the c++ version doesn't

        Comment


          #5
          I changed the name of the function from OnOverlap to MyOverlap, to avoid a naming confusion with the actor. Still no luck.

          All I'm trying to do is bind a function to the components on overlap event

          Also I keep getting this

          LogOutputDevice: Error: Ensure condition failed: this->IsBound() [File:E:\Programs\Unreal\UE_4.23\Engine\Source\Runtime\Core\Public\Delegates/DelegateSignatureImpl.inl] [Line: 1136]
          LogOutputDevice: Error: Unable to bind delegate to ' MyOverlap' (function might not be marked as a UFUNCTION or object may be pending kill)

          Comment


            #6
            Bumb. This is what I'm trying to implement

            https://docs.unrealengine.com/en-US/...lap/index.html

            as seen in this tutorial
            https://www.youtube.com/watch?v=84B22sP2L1M

            The function is a member of UPrimitiveComponent, and this on all collider components, including StaticMesh.

            Ultimately my goal is to setup a component to act as a interface for game logic, a "Hitable" component, which will respond with a "hittee" component collides with it. But in order for this to work, I need to bind a function to the OnComponentOverlapEvent of the other uprimitivecomponents of the actor. However, what I have found is the event itself seems to broken and wont fire, no matter what I try, despite the blueprint version of OnComponentOverlapEvent firing correctly. I don't what I'm missing. I have made sure it check it the actor is pending kill. I have made sure that generate overlap events are turned on for both objects.

            I;ve followed the tutorial above exactly.

            Does anyone know what I need to do. Because all the documentation hasn't provided an answer.

            Comment


              #7
              Your signature is fine, try:

              FScriptDelegate CollisionBeginOverlap;
              CollisionBeginOverlap.BindUFunction(this, TEXT("OnEnterCollision"));
              MyMesh->OnComponentBeginOverlap.Add(CollisionBeginOverlap);
              SolidGasGames

              Comment

              Working...
              X