I’m pretty new to c++ programming in ue4. I’m having some trouble:
I initialized Shotgun and RPG in the character.h.
In the constructor, I set Shotgun as False and RPG as true. this is the constructor, right?
I then made it so when I press 2, it sets Shotgun as true and RPG as false.
But when I press 2, everytime I fire afterwards, RPG is still coming as true and Shotgun as false.
When I press 2, I set shotgun to true and I check if shotgun is true. If so, I print out “shotgun is true”, so I prove that shotgun is true. I also set RPG to false.
However, when I press LMB, I check if RPG, and if so, it prints “not”. (to symbolize that shotgun is false, which I also verified.)
Just a heads up, Constructors in UE4 are slightly different than normal C++ just due to the Lifecycle of an Actor and BP exposed variables. If you set a value to false in the constructor, but the Blueprint asset marks it as true, it’ll start false but end up true after PostInitProperties/PostLoad. It’s generally a good idea, for Actors at least, to move any initialization from the constructor into BeginPlay / PostLoad / PostInitProperties (if you’re new, I’d just toss it in BeginPlay).
This is where it prints that Shotgun is true, proving that it at least changed for the function. If I had to summarize my problem completely, it would be that changes I make to a function only change the function itself and don’t seem to actually carry out.