Unreal Engine (UE4) Custom Blueprint Type Converter
Preface
In blueprint development, many people should have encountered the need to print integer data to the screen. We know that the blueprint output log node can only output string type data. If you want to output integer data, this is not allowed from the perspective of strongly typed language features. But in actual use, blueprints only need to drag and drop to complete the operation. This is why blueprints are easy to learn.
In fact, this is not a function that should be taken for granted. The main reason why blueprints are always said to be simple is that the designer has thought of all your needs, making you feel that these are all taken for granted when using them. The advantage is that it is simpler, but the disadvantage is that you will become more and more dependent on these designers.
If I add my own type, can it be converted into a string? Or even other types? Of course it is possible. In fact, if we hover the mouse over the conversion node, you will find the secret!
From the figure, you can see the source code location of the node, jump to the source code
Steps
1. Create a blueprint function library class (must be completed in the blueprint function library class)
2. Design a custom type (the type is arbitrary, must be recognizable by the blueprint, and declared in the header file), taking the custom structure as an example.
|
|
3. Write the conversion function (The function needs to be added to the blueprint function library)
Code in the header file
|
|
Code in the source file
|
|
4. After compiling, you can use the conversion node in the blueprint
Of course, you can design any conversion type you want, as long as you need
Tips
- The function must be written in the blueprint function library
- The function must be a public static member function
- The function name is arbitrary, and for clarity, it is recommended to follow the engine naming format structure
- The conversion target type must be the return type
- The source type must be the first incoming parameter (there can be multiple parameters)
- The function must use the BlueprintPure tag to hide the input and output execution pins
- CompactNodeTitle = "->" can be omitted, this tag is used as the node title name
- The BlueprintAutocast tag must be retained, marking it as a conversion node
Engine version: 4.27.2