How can I create Custom events for UObject?

Hi guys,

I am using a class derived from UObject for my functionality implementation. I have a custom event

UFUNCTION(BlueprintNativeEvent, Category = "Magic")
	void OnLaunch();

and I give it some default implementation:

void UWolfdaleSpell::OnLaunch_Implementation()
{
	if (GEngine != nullptr)
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Default OnLaunch implementation"));
}

Then, I make sure it is being invoked in the blueprint, and override its implementation

However, it always gives output ““Default OnLaunch implementation””, which means it always invokes default event code. In the past, I derived my class from Actor, and the event override was working fine. Now that it’s UObject it does not work. What do I do?

Here is the way how I instantiate my object before calling its event (maybe I do it wrong?) :

void AWolfdalePlayerController::AddSpell(TSubclassOf<class UWolfdaleSpell> Spell){
	//ADDS TO ZERO INDEX SPELL FOR NOW
	UWolfdaleSpell* cSpell = NewObject<class UWolfdaleSpell>(Spell);
	Spells = cSpell;
}

This is a blueprint-called function, which adds a spell of a specific class, listed in the argument, to the array of spells that playercontroller would have.

#BlueprintImplementableEvent

#Instead of this

UFUNCTION(BlueprintNativeEvent, Category = "Magic")
    void OnLaunch();

and I give it some default implementation:

void UWolfdaleSpell::OnLaunch_Implementation()
{
    if (GEngine != nullptr)
       GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Default OnLaunch implementation"));
}

#Do This

/** LAAAAAAUUUUNNNCH! */
UFUNCTION(BlueprintImplementableEvent, meta=(FriendlyName = "Do The Happy Happy Launch"))
virtual void OnLaunch(FVector LaunchVelocity);

//there is no .cpp implementaiton

#Do Note this is .h only, no .cpp!!

You don’t need or ever use a default implementation with BlueprintImplementableEvent!

#Still Call the Event in Code

//.cpp to trigger BP event
    this->OnLaunch(TheLaunchVelocity); 



//this-> is my personal syntax to know it is BP Event

#Parameters

I’m just showing you that you can send data to the BP from CPP, you dont have to include the LaunchVelocity parameter


#My Wiki Tutorial

Still not working :frowning: The call to OnLaunch() does nothing, without any kind of error messages whatsoever.

you need to post your code as it is now, in its entirety, after switching to using my above method.

you should not have a default implementation

I do what I am describing to you in this post all the time and it works great

Ok, here u go:

I make the event in Wolfdale spell, then I make it possible to add new spells into the Controller class, then I create those spells using NewObject() funciton in the Controller. Then in blueprints I use that functionality such that I add new spell to the controller and bind its’ Launch func to G keypress. In the spell blueprint (testspell) I implement the OnLaunch() event, which is being called straight from Launch() func. And it does not work. :frowning:

Some more pics

And lastly: