How do I make a custom blueprint event global?
So for example:
/*
* Primary Fire - Fired from CharacterPlayer in C++
*/
UFUNCTION( BlueprintImplementableEvent, Category=Default)
void PrimaryFire();
How would I make this reachable from all blueprints?
Thanks,
Jon
Hi Jon,
We don’t have a built-in way to broadcast an event to every Actor, but here are a couple ideas you could try to make it work yourself.
a) Create an interface with your event in it. Implement the interface for any actor that wants to implement the event. Use something like UGameplayStatics::GetAllActorsWithInterface() when you want to broadcast your event.
b) Create a component with your event. Add the component to any actor that wants to implement it. Maybe register your component with something global-ish like the GameState, and then use that short list of components when you want to broadcast the event.
Cheers!
Hey Jonathan,
Thanks for your report! I believe the answers in the following thread should put you on the right path for accomplishing what you are trying to do, specifically Nick Whiting’s answer:
https://rocket.unrealengine.com/questions/6590/question-custom-blueprint-nodes.html
If the information in that thread doesn’t prove helpful to your goal, please let us know and we can dive a little deeper.
Thanks!
-Steve
Hi Steve,
Thanks for the reply.
When I try creating a BlueprintImplementableEvent in my custom BluePrint Library I am unable to find the PrimaryFire event in any BP. I am able to place it in specific classes in C++ and it works as shown in that thread. To be clear, I’m looking to make this event completely global and accessible from all other BP’s.
Thanks,
Jon
Hey Jon,
In that same thread another contributor, Nathan Lyer, posted a link to a tutorial on the Rocket forums (I’ll link it again below). He lists out a good walk through that should enable you to create a function (note that you need a .h and .cpp as Nick mentioned) that is accessible to be called by any other blueprint in your project. If you have tried Nathan’s steps and are still unable to make a global event/function, would you mind posting your code for both your .h and .cpp files?
Nathan’s tutorial: http://forums.epicgames.com/threads/972861-TUTORIALS-C-for-UE4-gt-gt-New-Equivalent-of-PostInitComp-amp-Tick-for-Anim-Blueprints?p=31682322#post31682322
Thanks!
-Steve
Hi Steve, I asked Nathan about this and he is also only able to create a global function, not a global event.
Here is my code:
#pragma once
#include "QUBEBluePrintLibrary.generated.h"
UCLASS()
class UQUBEBluePrintLibrary : public UBlueprintFunctionLibrary
{
GENERATED_UCLASS_BODY()
UFUNCTION(BlueprintCallable, Category="QUBE")
static void NumOfCubeColors(int32 Blue, int32 Red, int32 Green, APawn* TargetPlayer);
/*
* Primary Fire - Fired from CharacterPlayer in C++
*/
UFUNCTION( BlueprintImplementableEvent, Category="QUBE")
void PrimaryWeapFire();
/*
* Secondary Fire - Fired from CharacterPlayer in C++
*/
UFUNCTION( BlueprintImplementableEvent, Category="QUBE")
void SecondaryWeapFire();
};
My NumOfCubeColors function works just fine as it’s BluePrintCallable, but any function that is set to BlueprintImplementableEvent does not appear in engine.
Thanks,
Jon
Dear Jon,
I posted a tutorial specifically about your issue.
I created a solution using Interfaces that is very simple code-wise, but very powerful.
Trigger Custom Global Actor Events Using UE4 C++ Interfaces
http://forums.epicgames.com/threads/972861-20-TUTORIALS-C-for-UE4-gt-gt-New-How-to-Tick-Mesh-Anims-Even-When-Not-Rendered?p=31703539&viewfull=1#post31703539
#Overview:
create an interface function that is your “event”
have actors implement that interface using multiple inheritance
when you want to call the event for the entire game world of actors
iterate over all actors
check if they have the interface / event
the run the even
Every actor creates their own version of the interface event of course
meaning each of your classes can indeed respond differently to the global event
Enjoooy!
#Thank You Epic
The core of my method is the InterfaceCast
which when called on different objects somehow gives me access to the subclassed / overrided version of the interface function / event
truly awesome!
![tyepicdevsheart.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/2/b/22ba011743f85d9e0d6c8c3399b7aec99f387b5f.jpeg)
Rama
Aha ok, Thank you guys much appreciated.