- Unreal Engine 4 Scripting with C++ Cookbook
- William Sherif Stephen Whittle
- 221字
- 2021-07-08 10:50:49
Creating a UFUNCTION
UFUNCTION()
are useful because they are C++ functions that can be called from both your C++ client code as well as Blueprints diagrams. Any C++ function can be marked as a UFUNCTION()
.
How to do it...
- Construct a
UClass
with a member function that you'd like to expose to Blueprints. Decorate that member function withUFUNCTION( BlueprintCallable, Category=SomeCategory)
to make it callable from Blueprints. For example, the following is theWarrior
class again:// Warrior.h class WRYV_API AWarrior : public AActor { GENERATED_BODY() public: UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Properties) FString Name; UFUNCTION(BlueprintCallable, Category = Properties) FString ToString(); }; // Warrior.cpp FString UProfile::ToString() { return FString::Printf( "An instance of UProfile: %s", *Name ); }
- Create an instance of your
Warrior
class by dragging an instance on to your game world. - From Blueprints, call the
ToString()
function on thatWarrior
instance by clicking on yourWarrior
instance. Then, in a Blueprints diagram, type inToString()
. It should look like in the following screenshot:
Tip
In order to call a function on an instance, the instance must be selected in the World Outliner when you start to type into the autocomplete menu in the Blueprints diagram, as shown in the following screenshot:

How it works…
UFUNCTION()
are really C++ functions, but with additional metadata that make them accessible to Blueprints.
推薦閱讀
- Java程序設計與開發
- 流量的秘密:Google Analytics網站分析與優化技巧(第2版)
- 劍指JVM:虛擬機實踐與性能調優
- Learning RabbitMQ
- Selenium Design Patterns and Best Practices
- Julia機器學習核心編程:人人可用的高性能科學計算
- Redis Essentials
- Python機器學習經典實例
- Kali Linux Wireless Penetration Testing Beginner's Guide(Third Edition)
- Unity 5 for Android Essentials
- Java:High-Performance Apps with Java 9
- Python編程從0到1(視頻教學版)
- 好好學Java:從零基礎到項目實戰
- Mastering React
- HTML+CSS+JavaScript網頁設計從入門到精通 (清華社"視頻大講堂"大系·網絡開發視頻大講堂)