How to create custom PlayerState and PlayerController in C++?
Hi everyone! I need to want to create a custom PlayerState and PlayerController but I don't know exactly what I should do. What steps I must follow?? I couldn't find anything about creating custom c++ player states or player controller. For example, I create a class that inherit from PlayerState and I add some floats to it (I want put it some character's attributes) and I modify the defaults PlayerState class to my own class (change it in projects preferences-> maps and modes) but know, the project crash so I must fail somewhere... Later, I really don't know how to link all this class (PlayerController, PlayerStates and Character) to work together. Could anyone help me with a little guide or a link to a tutorial? Thanks in advance!!!!
PD: the code I had in CharacterStats (PlayerState inherit):
I comment some parts because I remove the class (a cause of the crash) but the only things that I add are the variables, rest is all like de defaults definition Unreal create when you create a class that inherit from PlayerState.
You already know a lot if you did it in blueprint, there exact same events and function available, 95% of all nodes in blueprints are direct C++ bindings, all events you use there are also avable and in most cases they have exact same names. The Target is a equivalent of object you calling function on, looking on type of Target pin you know in which class this function is. Look on API refrence:
All virtual functions (with V icon) you see are overable and you can use them as events. You override function like this here BeginPlay for example
.h (in class decleration):
Doing that Super call is super importent as it calls overrided code and if oyu dont do that you may block some of the engine code from execution, consequance of not doing so in BeginPlay for example is BeginPlay event not being called in blueprint based on your class, as in AActor code in BeginPlay() it calls blueprint event for BeginPlay.
As for crash you would need to show your code so we can see whats wrong. see the logs in Saved/Logs to see crash info (sometimes it gives you direcly information what went wrong) or run debugger and VS will show you like that causes the crash in stack.
answered Apr 25 '18 at 11:30 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here