Blueprints, Empower Your Entire Team With BlueprintImplementableEvent
Contents
[hide]- Overview
- Providing Blueprints With Data And Critical Timings
- PlayerController.h
- Tick Function
- Sending Data to Blueprints From C++
- Calling a BlueprintImplementableEvent in Blueprints
- 4.8 Standard, Non Virtual
- Debugging BlueprintImplementableEvent
- C++ to BP Interface
- Blueprints For More Than Prototyping
- Use Blueprints & BlueprintImplementableEvent to Empower Your Entire Team
Overview
Dear Community,
Here is perhaps the most powerful thing you can do as a c++ programmer for blueprint programmers!
So you've created your awesome new amazing C++ system,
but how do you tell the blueprint world when critical events occur in your C++ system?
You need to not only be able to have blueprint programmers call functions that use your C++ system,
you need to be able to spontaneously provide info to blueprint graph system, based on Run-Time events.
This is where BlueprintImplementableEvents come into play!
Providing Blueprints With Data And Critical Timings
Using the BlueprintImplementableEvent you can not only tell blueprints when a critical game event has occurred that your awesome C++ system is tracking / creating,
you can also send variable data to blueprints!
Example code below!
PlayerController.h
.h
/** Player's Health is Currently Above 50! Returns player's exact current health for convenience. This function runs every tick that the player's health is high enough! Play healthy sounds here. */ UFUNCTION(BlueprintImplementableEvent, meta=(FriendlyName = "Player Health ~ Player Is Healthy Tick")) void PlayerIsHealthyTick(float CurrentHealth);
.cpp
void AYourPlayerController::PlayerTick(float DeltaTime) { Super::PlayerTick(DeltaTime); //======================== // BP Interface if(Health >= 50) { this->PlayerIsHealthyTick(Health); } //======================== }
This
this->PlayerIsHealthyTick(Health);
I personally use this-> to tell myself I am not actually calling a C++ function, but am sending info to BP.
You could exclude the use of this->
Tick Function
Note that the sample code is sending an event to blueprints every tick!
You can call BlueprintImplementableEvent's any way you want,
but I used this example to show a constant interfacing from c++ to blueprint graphs.
Sending Data to Blueprints From C++
Notice how the player's current health is being sent to blueprints as a function parameter!
You can pass any data you want from C++ to blueprints this way!
Calling a BlueprintImplementableEvent in Blueprints
Make sure to include BlueprintCallable if you want to also call your event in Blueprints!
UFUNCTION(Category = "Player Health", BlueprintImplementableEvent, BlueprintCallable) void PlayerIsHealthyTick(float CurrentHealth);
4.8 Standard, Non Virtual
As of 4.8 BlueprintImplementableEvents should not be made virtual!
From the 4.8 Engine upgrade notes:
Removed "virtual" keyword from several engine-level BlueprintImplementableEvents to conform to the new "BlueprintImplementableEvents should not be virtual" standard.
Debugging BlueprintImplementableEvent
Void Return Value
If you are having trouble getting a BlueprintImplementableEvent to show up in the blueprint graph, try making sure that your return type is void.
If you do have a return type, your BP implementable event will show up in the left panel and you can right click to implement it.
Do Not Pass by Non-Const Reference
Also, I dont recommend trying to pass data to blueprints using non-const reference.
either use const reference or no reference at all.
/** Player's Health is Currently Above 50! Returns player's exact current health for convenience. This function runs every tick that the player's health is high enough! Play healthy sounds here. */ UFUNCTION(BlueprintImplementableEvent, meta=(FriendlyName = "Player Health ~ Player Is Healthy Tick")) void PlayerIsHealthyTick(float CurrentHealth);
/** Player's Health is Currently Above 50! Returns player's exact current health for convenience. This function runs every tick that the player's health is high enough! Play healthy sounds here. */ UFUNCTION(BlueprintImplementableEvent, meta=(FriendlyName = "Player Health ~ Player Is Healthy Tick")) void PlayerIsHealthyTick(const float& CurrentHealth);
C++ to BP Interface
I am using the term interface loosely here, to describe how it is that you as the C++ programmer of an awesome new game mechanic can give Blueprint users all the info they need about what your C++ system is doing!
You can do all the core calculations in C++, and just send blueprint graphs the results!
Blueprints For More Than Prototyping
Using BlueprintImplementableEvent's I can now show you that blueprints are amazing for far more than just prototyping game logic that should then be re-written in C++.
Using BlueprintImplementableEvent's, you can actually build a complex low-level c++ system,
and then provide the blueprint graphs with all the critical access points and information needed,
so that blueprints can fully extend and utilize the core C++ system!
Use Blueprints & BlueprintImplementableEvent to Empower Your Entire Team
In this way, you as a C++ programmer can empower your entire team to access, utilize, and extend a core C++ system in blueprints!
This is my favorite thing about the synergy of C++ with Blueprints!
You can write the core system in C++, and then give all of its power and new creativity to the blueprint programmers to take in all sorts of new directions!
Enjoy!
'게임엔진(GameEngine) > Unreal4' 카테고리의 다른 글
C++에서 블루프린트 함수 호출하기 .2 인자와 같이 넘기기 (0) | 2016.07.08 |
---|---|
C++에서 블루프린트 함수 호출하기 .1 (0) | 2016.07.08 |
델리게이트 (Delegate) (0) | 2016.07.07 |
UGameInstance, 싱글톤 생성 부모 클래스 (0) | 2016.07.06 |
언리얼4에서 C++ 로 싱글톤, Game Instance (0) | 2016.07.06 |