I have a character class and want to show the current ammo via a UI widget blueprint. In my characters header file, I have defined my CurrentWeapon variable as:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Player") ASWeapon* CurrentWeapon;
The ASWeapon class has the following variables:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon") int TotalAmmo; UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon") int MagazineSize; UPROPERTY(EditDefaultsOnly, BlueprintReadWrite, Category = "Weapon") int AmmoInMagazine;
The UI blueprint has a text field whose value is binded to a function which looks like this:
Running the game, I get the following error: Blueprint Runtime Error: “Accessed None trying to read property CurrentWeapon”. Blueprint: WBP_Ammo Function: Get Ammo Text Graph: Get_Ammo_Text Node: Return Node
I am absolutely sure CurrentWeapon is never null as its content are rendered on the screen and logged properly in the Output Log. What am I doing wrong? Thank you!
P.S. Is there a way to fetch the player character in the UI blueprint, independent of the player index? In other words, this widget is always going to display the ammo of player 0, while the other players’ ammo will never be displayed to them.