How to Make Global Functions and Structs?
So I've gone from zero to 60 in the last week in terms of understanding how to create UFunctions, UClasses, UProperties, etc. I'm also new to C++, but pretty comfortable with some other languages so programming is nothing new.
However, What I really am trying to grasp right now, I haven't been able to find any good tutorials for.
I want to create some "BluePrint Function Libraries" so that I can have some global Blueprint Functions available for controlling motion and other stuff. However, I need to be able to handle some pretty complex unique coordinate system transformations - so I need to use C++ UFunctions to handle those.
Is there a way I can either make Global UFunctions or Global Structs that can appear in any Blueprint?
OR Conversely, can I make a Custom Class derived from a "Blueprint Function Library" to accomplish the same thing? Here's what I tried that DID NOT work:
Creating New Class Based on Function Library
Name and Public/Private folders
Then here is the most simple example I could try (compiles fine):
Header: #pragma once
This should in theory allow me to make BP Function Library from this new derived class... But when I reopen the project and look for it, nothing comes up:
There's also no hint of "avMyTestFunction" anywhere in the project, nor the Struct I defined.
Anyway, I either want to know why this isn't working - or some alternative for creating global "Uthings."
asked May 23 '15 at 07:40 PM in C++ Programming
You just have to create the class of your custom BP function library and then you will be able to use those functions in your BPs, there is no need to create a new instance.
To create global structs I would encourage you to just create a simple header file in your public code, then include that header in your main project header to you will be able to have access to the structs from every where. This way you have visibility in both native code and BluePrints.
Native (C++) Blueprint Function Library
The next code is basically the same as in Ramas tutorial. We just add the header file (.h) and the implementation (.cpp). The next think is simple, compile your project.
Now we have compiled the code (it hopefully went all ok :D). The next step is to simply launch the editor and you are ready to use your functions in your Blueprints. This might seam strange but you do not have to create a child of UMyBlueprintFunctionLibrary in fact the engine wont let you to do so. The next screenshot is directly after I compiled the engine, just right click in any Blueprint and search for your new functions.
Notice the 'Save String to File' function?
Native structs to be used in Blueprints
When you setup a C++ project Unreal will create a main header file for your project (normally it's just the name of the project itself). You will have something like this:
What I normally do for structs that I consider global and so I will use them a lot in my code and in Blueprints (if it's only for Blueprints you can add them nearly everywhere but the sake of clearness we will discuss the nice way here) is to add them in a separate header. The next code outlines the use of the types header and the projects main header file.
FNameItem is a struct you can use nearly from every where in your code and in Blueprint.
Follow this question
Once you sign in you will be able to subscribe for any updates here