I have a function in my C++ GameMode for the map, which I’ve given the UFUNCTION(BlueprintCallable) macro. I call the function from my level blueprint using a Begin Play event.
The function doesn’t respond at all even though I can see the pins firing in the BP at run-time.
SOLUTION: Originally in my target pin I promoted it to variable since I didn’t know how I was supposed to get the reference to my C++ game mode. This time I used the Get Game Mode node, casted it to my implementation, and used its output pin as the reference. Now my function works. I really don’t get why I had to do it in such a roundabout way and thought that promoting the target variable would’ve worked. Anyone care to explain?
Whoops that’s embarrassing, but yes I definitely have it the right way round in code. I put breakpoints on the function itself and they’re not triggering so I’m not sure what the problem is.
Is it because I’m trying to access the gamemode through the level blueprint? Is there some special rule against this?
I recreated the issue in a new project. The file size is almost a gigabyte even though there’s no starter content. How do I reduce this and upload it for you?
Edit: I created a C++ class derived from the default APawn and added my custom function. In the editor I created a BP derived from my custom APawn and called the function.
This worked, but in my original case calling a function that’s not directly defined by the class of the BP doesn’t seem to work. Why is this?
Edit: Thanks for your help, found a solution, but I don’t understand it. Any chance you could explain?
Fun fact: “Header Code” is C++, what include does is paste the code from file to point there include is, it does not need to be header file but practically anything. If you would place code in header file in .cpp file instead of using include the result would be the same… in normal C++, since UHT needs headers to be in header file. Header files exist because otherwise you would need to repeat and repeat headers in each cpp file, include makes things cleaner.
For the future: You only need to send us the Source, Content, Plugins and Config folders and the uproject file. If that is still too big remove all meshes and textures etc.
You created a variable but did not initialize it, so it’s value was a nullptr. If you promote an input to a variable the blueprint system can’t know it’s value, so it is initialized with a default value - in this case the nullptr.
Do you know that you can debug blueprints? You can set a breakpoint in your custom node and then inspect the value of the variables. That way you could have seen that the variable holds a nullptr.
Note: A screenshot of the call in the blueprint would have been a great help for us helping you. Every bit of information you can provide when asking questions is useful.
Yes, but if he puts the .cpp code above the .h code (which will happen if he switches them like he did above and still use include header.h in the cpp file), wouldn’t this cause errors, because the compiler finds a definition before it findes the actual class and function declaration?