Announcement

Collapse
No announcement yet.

OnClicked Event Not Firing

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

    OnClicked Event Not Firing

    In this program, what I want to have happen is for my cursor to be able to lift a block once it's been clicked. The static mesh component (the block) is part of my MainPlayer character, so all of the code is in my MainPlayer.cpp. So first I create a UStaticMeshComponent called PuzzlePieceMesh in the constructor.

    PuzzlePieceMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PuzzlePieceMesh0"));

    Then I include the OnClicked event in the constructor as well...

    PuzzlePieceMesh->OnClicked.AddDynamic(this, &AMainPlayer::CompClicked);

    which should call CompClicked function if my mouse clicks the block

    void AMainPlayer::CompClicked(UPrimitiveComponent* ClickedComp, FKey ButtonPressed)
    {
    UE_LOG(LogTemp, Warning, TEXT("CompClicked..."));
    PieceClicked();
    }


    However, this function is not being called, leading me to believe it's a problem with the mouse interface.

    I've checked to make sure the following was true:
    - Show Mouse Cursor is true (Within PlayerController BP)
    - Enable Clicked Events is true (Within PlayerController BP)

    - PuzzlePieceMesh has a static mesh with collision (Within MainPlayer BP)

    - In project settings->input->mouse properties->Use Mouse for Touch is false

    - Default Pawn Class is MainPlayer BP
    - Player Controller Class is PlayerController BP
    - Default Gamemode is also set correctly

    I'm not sure what else to check, so help would be appreciated on how I can get the OnClicked event to fire upon clicking the component. I'll answer any questions to best of my ability and edit this if I figure it out myself.

    Thanks.
    Last edited by Pirate1029; 10-09-2019, 02:46 PM.

    #2
    Just going by the code here the method name differs from what you are trying to bind to. If that doesn't work try the click signature with only the PrimitiveComponent as a parameter.
    .AddDynamic(this, &AMainPlayer::CompClicked)
    void AMainPlayer::PawnClicked

    Change one of these: PawnClicked <=> CompClicked
    SolidGasGames

    Comment


      #3
      Originally posted by Telimaktar View Post
      Just going by the code here the method name differs from what you are trying to bind to. If that doesn't work try the click signature with only the PrimitiveComponent as a parameter.
      .AddDynamic(this, &AMainPlayer::CompClicked)
      void AMainPlayer::PawnClicked

      Change one of these: PawnClicked <=> CompClicked
      I must have forgotten to change save my changes after making an edit from PawnClicked to CompClicked. Thank you, it's been fixed, but the overall question of why the OnClicked event isn't working still stands.

      Comment


        #4
        Try setting collision on the mesh to BlockAll, read a post where that helped.
        SolidGasGames

        Comment


          #5
          Originally posted by Telimaktar View Post
          Try setting collision on the mesh to BlockAll, read a post where that helped.
          I tried that, but the results are the same, the mesh doesn't detect my cursor.

          Comment


            #6
            UPDATE: I've recreated the project with the same settings and code as I've had before, and suddenly it worked. I must have deleted something I shouldn't have to make the OnClicked event not respond correctly. Thanks for the replies, but consider this thread closed for the time being.

            Comment

            Working...
            X