Need help with C++
I just started learning C++ and need some help.
First let me show you what I'm trying to accomplish in C++ that I did in Blueprint. I created a Blueprint Function Library in witch I have a (pure) Blueprint function that just returns an AI Controller at a given index ("Player" is the name of the Blueprint Function Library I created):
As you can see I'm casting to my game mode to access an Array of AI Controllers that is derived in the TestMode with is also a Blueprint:
This is what the "TestMode" looks like. When the game begins it is going to spawn AI players, so I created a function within TestMode called "Create AI Players":
The function spawns AI Controllers and stores them in an array which is the array I mentioned previously.
Now I was thinking, that it would be better to recreate that function in C++, so I can use it in C++ and also in Blueprint. So I created a Blueprint Function Library in C++ and I decided to create a game state instead of game mode, but it would hold the same functionality.
This is the header of the game state I called "TEST_GameState":
... and cpp file:
The Blueprint Function Library is the important part where I need help. I called it simply Library.
Notice, I added static so in Blueprint it'll get rid of the "Target" pin.
And for the cpp file I need help:
How would I recreate the Blueprint Function in C++?
I'm currently not at home, so I can only show you the way on how to accomplish what you want to do:
To get a reference to the GameState, you'd need to have a UWorld reference. You don't have a valid world reference though, as the blueprintlibrary just doesn't have a world context. So you'd need to use an objectiterator (rama has a nice tutorial for it, look it up, it's really helpful :) ) to get a reference to the world and then get a reference to the GameState from that (MAYBE you can directly use ObjectIterator for your GameState, I don't really know this though :( ).
You'd then have to cast your GameState reference to ATEST_GameState and then you can access the AIControllers array.
I hope this was somewhat helpful. If you need specific code parts, I can help you with that, but the best practice is probably doing it yourself!
Good luck! Hope I could help! :)
answered Apr 01 '15 at 04:34 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here