C++ Delegate not being called

I’ve been working on converting some blueprint logic over to C++. One of the things I have is a button. The button can be pressed in VR and has a delegate that is called to notify any registered functions that the button press occurred. Here is how the delegate is declared in the AButtonItem.h class.

#pragma once
#include "BaseItem.h"
#include "ButtonItem.generated.h"


class AButtonItem : public ABaseItem

	UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Touch)
	float myMaxButtonPress;


	UPROPERTY(EditAnywhere, Category = Callback)
	FButtonItemPressedSignatrue ButtonItem_OnPressed;

The delegate’s broadcast function is then being called when the button is pressed like so:


(This function should defiantly be called because I have a debug statement that prints right before the call. Its also important to note this was all working when it was blueprint logic.)

Here is where I try to register with the delegate and how I declared the function that will be called:


void OnNextBladeButtonPressed();


void AWeaponMaker::BeginPlay()

	TArray<USceneComponent*> weaponMakerComponents;
	this->GetRootComponent()->GetChildrenComponents(true, weaponMakerComponents);

	for (int componentIndex = 0; componentIndex < weaponMakerComponents.Num(); componentIndex++)
		if (weaponMakerComponents[componentIndex]->GetName().Equals("NextBladeButton") == true)
			myNextBladeButton = (AButtonItem*)weaponMakerComponents[componentIndex];

	if (myNextBladeButton != NULL)
		myNextBladeButton->ButtonItem_OnPressed.AddDynamic(this, &AWeaponMaker::OnNextBladeButtonPressed);


I put a breakpoint and a print statement in the function OnNextBladeButtonPressed so I should immediately know when it works but its never happening. I also re-created the blueprint itself from scratch but still no luck. Sometimes on compile I get a crash due to the InvocationList being invalid but I haven’t found much info on that issue either. Bottom line is, OnNextBladeButtonPressed is not getting called when it should be.

Are you sure your listener is actually being added correctly? If ‘myNextBladeButton’ is null then that would explain the problem so first make sure that your BeginPlay logic is correct.

Personally I’d use FindComponentByClass rather than manually looping through components. It’s less error prone than checking for component naming too. AActor::FindComponentByClass | Unreal Engine Documentation

Thanks for taking the time to respond to this weird issue, I defiantly appreciate the input.

I tried using FindComponentByClass but then I wont be able to specify the name of the component I want (the blueprint has multiple buttons). I double checked to see if the button is not null and it is infact not null (at least according to the debugger), here is a screenshot of me stepping through the debugger: