Title: Coin Collection UI Displays Duplicated Text
Brief Description of the Issue
At the start of the game, the number of collected coins is displayed on the screen as “Coins = 0.” However, when the player collects a coin placed in the stage, “Coins = 1” appears overlapping below the “Coins = 0” text.
(Only the number is stored as a variable.)
I have tried various solutions but have not been able to resolve the issue. I would appreciate any help you can provide.
Details:
◆Creating the Widget
1)I created a simple UI in a Widget Blueprint to display the number of collected coins.
※Components:
・Canvas Panel
・Image
・Text [WBP_Coin_Count]
2)I initially set the “Text” property of Text[WBP_Coin_Count] to “0.”
3)I checked “Is Variable” for Text[WBP_Coin_Count] and created a Text-type variable.
4)I named this asset “WBP_Coin.”
◆Coin Blueprint (Displaying the UI)
1)In the BeginPlay event, I connected “Create Widget” and set the Class to “WBP_Coin.”
2)I promoted the “Return Value” from “Create Widget” to a variable and named it “WBP_Coin_02.”
3)I then connected “WBP_Coin_02” to “Add to Viewport.”
◆Coin Blueprint (Updating the Coin Count Variable)
1)In the ActorBeginOverlap event, I connected “Destroy Actor.”
2)After that, I retrieved “GM Coin Num”, a variable previously created in GameMode to store the coin count, added 1 to it, and stored the updated value back in “GM Coin Num.”
3)Then, I connected “SetText (Text).”
※Additional Notes:
・For the Target, I referenced “WBP_Coin_Count” from the “WBP_Coin_02” variable.
・For “In Text,” I converted “GM Coin Num” to text using “ToText (Integer)” and connected it.
◆Debugging Feature
After “SetText (Text),” I added a “Print String” node to display the current coin count using “GM Coin Num.”
※Additional Notes:
As far as the print strings are concerned, the variable “GM Coin Num” just stored the number of coins.