This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
So I'm working on a game with a weapon system. Each weapon has its own type of ammo. I want to create a pointer variable that, instead of having a value in and of itself, it instead points to the int for the active weapon's ammo. Here are my variables.
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "WeaponStats")
int shotgunAmmo = 10;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "WeaponStats")
int rocketAmmo = 3;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "WeaponStats")
int* ActiveAmmo;
I'd ideally set the pointer to link to the ammo types like this:
void ATopDownCharacter::SwitchWeapon(TEnumAsByte<Weapon> WeapToSwitchTo) {
WeapEnum = WeapToSwitchTo;
switch (WeapToSwitchTo)
{
case Weapon::Pistol:
fireRate = fRatePistol;
PrintScreen("switched to normal");
ActiveAmmo = 0;
break;
case Weapon::Shotgun:
fireRate = fRateShotgun;
PrintScreen("swithc to spread");
ActiveAmmo = &shotgunAmmo; //active ammo refers to shotgun ammo
break;
case Weapon::Rocket:
fireRate = rRateRocket;
PrintScreen("swithc to rocket");
ActiveAmmo = &rocketAmmo; //active ammo refers to rocket ammo
break;
default:
break;
}
}
This is so I can write more efficient code for stuff like displaying the remaining ammo for the current weapon (bind a widget to ActiveAmmo instead of doing a switch statement on the current active weapon) or make updating ammo values easier.
void ATopDownCharacter::UpdateAmmo(int AmmoAmnt)
{
ActiveAmmo = AmmoAmnt; //This would change whatever is currently set as active ammo by the inputted amount
return;
}
However, I get an error at my definition of the ActiveAmmo pointer, stating
Inappropriate "*" on variable of type "int32", cannot have exposed pointer to this type
I have no clue what to do at this point. Am I just fundamentally misunderstanding the use cases of pointers? I've been able to declare pointers for stuff like StaticMeshComponents with no issues, so I don't really get what the difference is between them and a simple integer.
Subreddit
Post Details
- Posted
- 6 months ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/unrealengin...