BlueprintNativeEvent vs BlueprintImplementableEvent

I have a projectile that OnHit will do some logic and will spawn a particle effect.
I want to keep the logic in c++ but I want to place the particle spawning within blueprints (for artists to use).

I’m not sure what is the recommended way to implement it, even after reading the docs here: Exposing Gameplay Elements to Blueprints | Unreal Engine Documentation

What I’m doing right now is with a BlueprintNativeEvent, that has a OnHit_Implementation method, and in blueprints I use “add call to parent” before spawning the particle effects.

It works but I’m not sure this is the right approach,
maybe I should just add an additional BlueprintImplementableEvent and at the end of the OnHit c++ method, I can simply call event.broadcast() to notify the blueprints that OnHit has happened.

Any suggestion?

1 Like

maybe I should just add an additional BlueprintImplementableEvent and at the end of the OnHit c++ method, I can simply call event.broadcast() to notify the blueprints that OnHit has happened.

That’s exactly how you should handle it. BlueprintNativeEvent is for situations where you provide default C++ implementation but give opportunity to override it in Blueprints.

Naming convention is that you prepend Receive in the “BlueprintImplementableEvent” name and set nice Blueprint name in meta (just like Tick is defined in Actor.h).

In your case:

virtual void OnHit();

UFUNCTION(BlueprintImplementableEvent, meta=(DisplayName = "OnHit"))
ReceiveOnHit();
4 Likes

Great! Thank you very much, I needed the Naming convention too!

so let’s recap, can you confirm that the following is right?

  1. I have a base class called SuperSpell, then a ProjectileSpell that inherit SuperSpell and spawn CustomProjectile.

  2. Create a blueprint from ProjectileSpell and another blueprint for CustomProjectile. (BP_projspell will spawn BP_customproj)

  • CustomProjectile will have a BlueprintNativeEvent OnHit, cause I want let the blueprints provide a custom implementation (the blueprint will first add a call to the parent).

  • The base class SuperSpell will have 1 BlueprintCallable method called CastSpell that in it’s implementation will call a BlueprintImplementableEvent called ReceiveCastSpell

  • now let’s suppose that while the spell is casting something happen.
    In this case I would provide a BlueprintAssignable property which is a DYNAMIC_MULTICAST_DELEGATE and use it with broadcast()

Can you confirm that this flow is correct?
I’m not sure if I should use the delegate, isn’t the same as having a BlueprintImplementableEvent??

Seems OK. Maybe I’d change point 3 to BlueprintImplementableEvent ReceiveOnHit.

It depends whether things that OnHit does in code must always happen. If C++ must always be executed then your approch creates the risk of someone forgetting to put “Call to parent” block in blueprint. With BlueprintImplementableEvent called by C++ code, there’s no risk, that c++ code won’t be executed.

Generally use BPNativeEvent when blueprint is meant to override the C++ code.

On the other hand, use C++ functions OnSmth + ReceiveOnSmth (BPImplementableEvent) when blueprint should extend what c++ code does.

When I worked at big UE4 game as programmer, we usually defined core logic in C++ and left extension points as BlueprintImplementableEvets as extension points for designers, who worked in Blueprints.

1 Like

finally someone who works in a way that makes sense! if you need a developer I’m in! ahahah

That being said, since you are that knowledgeable can I ask you when should I use a delegate instead of BlueprintImplementableEvent?
it is just for the multicast?

oh and another thing if I may, where to put the Destroy method?

We generally created delegates when designers requested, that they want a way to be informed about something happening in the object from other objects.

E.g. lets say, that you want a lamp that blinks every time someone nearby casts a spell. Spellcasters will have a dispatcher, and lamp will add its delegate to the dispatcher in spellcasters that enter lamp’s influence volume. Once they leave the volume, or get destroyed inside, lamp will remove it’s delegate.

Generally, how exactly you should divide things between C++, blueprints, NativeEvents, BPEvents and dispatchers is not really well defined. It’s closely related to how your team looks like. Are people more comfortable with code or blueprints? Do BP people produce something sensible, or they make spaghetti? If they aren’t too competent, you’d like to put more stuff to code and reduce the amount of damage that BP people can do. It’s kind of philosophical.

Blueprints and UE4 are quite new thing, and there are no clear guidelines on how you should do things. I tend to look at Epic examples and Unreal Tournament code for reference.

1 Like