Creating Widget Blueprint With Variables from C++

**Here is my code, I am setting the value of Coins 96 but the result in widget blueprint is being 0. can anyone solve the problem? I will be appreciated


Are you setting “New var 0” to an instance of a class? If it is not valid it will just print out 0.

@GarnerP57 hey thanks for answering, how can I do that?

Well first you need to get a reference to the instance of “APickup” you are interested in. There is many ways to this.

If you already got a reference to the pickup on the Character just get it through the Character like “GetPlayerCharacter” and cast it to your type of character and get the pickup reference to be Set in your widget.

If the pickup reference is not saved on the character but the pickup is Attached to the character you can find it with “GetAttachedActors”

If the Pickup spawns its own widget when it gets Picked up by someone it could also be done by using “CreateWidget” and the return value is the Widget and you then have APickup set itself (self) as “New var 0” on the widget. This is the reverse of the two other examples since now the work is done in the Pickup Blueprint instead of in the Widget Blueprint.

ps. Make sure you rename “New var 0” to something meaningful.