Hi all,
While attempting to add a new functionality to the Toon Tanks exercise, I have found that the engine crashes and I do not know how to go forward.
I am attempting to add a function to count the amount of projectiles the tank has fired, while having a widget on the screen that tells the user how many projectiles are available.
For this, I have done the following:
-
In Tank.h, I have added 2 private variables, Max Ammo, and Current Ammo:
-
In Tank.h, I have added the following public function:
-
In Tank.h, in BeginPlay, I assign the Current Ammo to be Max Ammo:
-
In the Fire function in BasePawn, I call the Tank function CountAmmo once I have checked that the projectile being fired belongs to the Tank and not the Tower:
This function is being called correctly from BasePawn, as I have introduced another UE_LOG within CountAmmo, and it is being correctly printed.
However, when I attempt to use the Tank private variable CurrentAmmo within the CountAmmo() function, Unreal Engine crashes.
I would like this function to count down every time the tank fires, and call the GameOver function from ToonTanksGameMode once the tank has run out of ammo. I have implemented it like this:
But in my testing it seems that any call to CurrentAmmo will generate a crash. Shouldn’t this variable be visible to CountAmmo(), as it is declared in Tank.h? Aren’t we doing something similar with the variable Health in HealthComponent.cpp?
Also, is this the best way to implement such a function? I tried to go from things we have done before, as I am not experienced in this engine.
Thank you for your time.