C++ - Change character health during game through InputComponent

Hello

I am trying to change my character’s health in-game. When I am pressing the 1 button on my keyboard the character’s class is changing to a knight. It works fine up until the moment that I included to change the character’s health to whatever the health in the knight class is. It triggers a break point (See image below). If I try changing the health of the character in my character’s constructor then there is no problem and the health is changed. Help would be very appreciated. If you need more details about the code/implementation I can provide these details!

Thank you for your time!

Hi ,

I’m not clear - what is the error that is triggering the breakpoint? If you can supply the error message, we can probably help better.

Just from looking at the code you have, I’m guessing the error is a null-pointer exception. At a guess, I wouldn’t be surprised if the getKnightClass() function is returning null. If your character class isn’t a Knight I could easily see that function returning null in order to indicate that the class isn’t a Knight. That’s just speculation though.

Anyway, like I said, we can probably provide more guidance if you supply the text of the error message.

Best regards,

I do not get an error message. The editor just gets stuck and a break point is triggered. I do not think that getKnightClass() is a nullptr. My m_pKnightClass object is being instantiated in CharacterClassType.cpp (See images of CharacterClassType.h & CharacterClassType.cpp).

EDIT:

I just realized that when a break point is triggered it actually states the error:

Error message: “this->m_pCharacterClassType->m_pKnightClass was nullptr.”.

Silly me! I think I’ll be able to fix that now on my own!

Thank you for your help!

Perfect! I’m glad it turns out to be a simple problem!

If it wasn’t a null pointer issue, it probably would have been a good deal trickier. :slight_smile:

Best of luck, and feel free to ask if you run into further problems!