Calling delegate fails in Blueprint implemented event from C++

Hi, for a project I have made a base-class (BouncingPadManager) in C++.

This base class is spawned and managed by the game mode.

#pragma once

// ...includes here

UCLASS()
class GAMEPROJECT_API ABouncePadManager : public AActor
{
	GENERATED_BODY()
	
public:	
	// Sets default values for this actor's properties
	UFUNCTION(BlueprintImplementableEvent, Category="Events")
	void OnScoreEvent(FTeamScore nativeSide, FTeamScore invaderSide); // no implementation in cpp

	UFUNCTION(BlueprintImplementableEvent, Category="Events")
	void OnGameEnd(); // no implementation in cpp
// ...here be more stuff
};

When a player scores this event gets called in the gamemode.

void ASportGamemode::AddScore(ETeams team, int point)
{
	// Notify BouncingPadManager
	BouncingPadManager->OnScoreEvent(nativeScore, invaderScore);
}

Now onto the weird part:
My BP_BouncingPadManager that derives from BouncingPadManager.cpp works on the following ways:

In begin play the delegate works fine and the output is as expected.

In tick the delegate also broadcasts fine and the output is as expected.

In the implemented OnScoreEvent (from the base c++ class) the delegate never calls anything so no output/desired behavior is produced. Any other code besides the delegates works fine(parameters were disconnected to simplify example.)

My question is: Why? and how can this be fixed.

Have you tried putting in a break point on OnScoreEvent? Is it being triggered?

Do you have c++ implementation code for OnScoreEvent?

  • OnScoreEvent_Implementation(FTeamScore nativeSide, FTeamScore invaderSide);

if so does it trigger?

A breakpoint in OnScoreEvent gets triggered, the C++ Doesn’t have an implementation so no nothing triggers. I have tried adding an implementation but the compiler won’t except it.

Error: BouncePadManager.cpp.obj : error LNK2005: "public: void __cdecl ABouncePadManager::OnScoreEvent(struct FTeamScore,struct FTeamScore)" (?OnScoreEvent@ABouncePadManager@@QEAAXUFTeamScore@@0@Z) already defined in BouncePadManager.gen.cpp.obj

I have found a way around the problem by just directly calling the function on a bouncing pad instead, but I just wish to know the reason why my initial approach didn’t work.

image

You should have it like this in the header

UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
		void OnScoreEvent(struct FTeamScore,struct FTeamScore);
	virtual void OnScoreEvent_Implementation(struct FTeamScore,struct FTeamScore);

then in the cpp

void ABouncePadManager::CalculateStatsBP_Implementation() {
// your code here
}

then from c++ try calling

	BouncingPadManager->OnScoreEvent_Implementation(nativeScore, invaderScore);

The virtual function is the one that can be overridden in blueprints.

I have tried to add these lines

image

void ASportGamemode::AddScore(ETeams team, int point)
{
	// Notify BouncingPadManager
	BouncingPadManager->OnScoreEvent_Implementation(nativeScore, invaderScore);
}

image

But now the compiler doesn’t want to compile it.

Your second parameter us not a struct, it’s an int.

Are the structs defined a unreal ustructs?

The parameters are right, I removed redundant code to show the problem. NativeScore and Invaderscore are of the correct datatype.

And somehow it works now, even though I have reverted everything to its original state.

Ill be closing this issue.

1 Like

It has to be a BlueprintNativeEvent so it can have a base C++ implementation, the BlueprintImplementableEvent doesn’t