Passing 'self' or 'this' from blueprint to C++ function
I need to use the
but I can't link my
How can I pass my self instance to the C++ function in order to call
asked Jul 04 '16 at 05:45 PM in C++ Programming
If you look at the many blueprint functions in GameplayStatics.h most of the functions need a valid world to do their things, these functions have one thing in common, they have WorldContextObject as its first function parameter and an additional meta: WorldContext="WorldContextObject", such as this one:
If you have ever used GetPlayerController in blueprint (you must certainly have) you should have noticed that the WorldContextObject parameter is not there in the input pin of the blueprint node, AND, you should also noticed that GetPlayerController can not be called on Object that does not override GetWorld(). This is how static blueprint functions get their world, and it's very convenient because Unreal does all the things needed to make sure blueprint user call the functions inside an object that has a valid world.
So, the solution to your problem would be to just change your function declaration to something like this:
and you can get the world in your function definition by using GEngine->GetWorldFromContextObject, such as this:
Also note that despite all the efforts from UnrealEd module to prevent blueprint user from calling the function from a non-valid non-world-context object, there is a possibility that the function is called from c++ which can be called from anywhere in the code, which means the WorldContextObject is not guaranteed to be valid nor related to a world. So you would want to check the validity of the World that you get from GetWorldFromContextObject function.
If you are making a single player game and you don't really care about the incoming multi world feature of Unreal Engine, you can get the current world instance using the global variable GWorld, although I really donot recommend this at all.
answered Jul 05 '16 at 08:33 AM
AFAIK, Blueprints cannot be used directly in C++ as types unless they are already derived from a C++ class. I'm fairly certain this includes passing a reference as a C++ parameter.
EDIT: If the blueprint in question is a UMG widget, this is not the case. You need to add some references to your Build.cs, and you will have access to Slate and UMG. If it's not, then the above should hold true.
Follow this question
Once you sign in you will be able to subscribe for any updates here