Int not displaying in widget?

Im trying to display my int value on text with a widget. I have the int set to 5000 but for some reason when i play it says 0. I dont have anything connected to this int yet. I tried doing a full cast in the bind and also a reference from a cast in the event graph. Ive done this before with no problems what am i doing wrong?

CredtisIngame.png

Is that int getting a value from sonewhere?

Ie let’s say your collecting bananas in world…

Player overlaps a banana. The Banaba casts to player controller and sets banana coubt int to add on to its current value then destroys itself

Next the umg to display the banana coubt for this score is using get text by casting to player controller to get banana count and sets its widget value of bananas… This value us then turned into text and returned for umg to display.

This is similar for handling animgraphs values for locomotion

i have the default value set at 5,000. The only place im changing is the value is when i build something. That takes away 100 credits, But that only happens when i use a certain actor ingame. So at this point it should display 5,000 but it says 0.

In 9/10 cases it’s an invalid reference, ensure it’s valid first. The output log should be spamming Accessed None at this point.

Yeah it does say accessed none. How do i fix this it says it for a normal cast also.

You created a *CharRef * in this blueprint but never Set it to anything - the engine does not know which character you mean.
You do not really want to cast anything in the widget itself as you’d be doing it every tick - quite inefficient.

One way to do it would be mark this variable as *Editable *& ExposedOnSpawn, go to the location where you spawn your widget and you will see that the create widget node has a new pin (RMB and Refresh if it does not), grab player character → cast to your character and plug it in the widget’s exposed node. Alternatively, you can do it in the widget’s constructor, you can find an example in the link I mention below (example 2)

As a side note, have a look here - these are different methods of binding data to widgets. The guide even states that the (this) method is the least efficient.

Hope it makes sense, let us know if it does not.

I already have it set on event construct. That is where the ref came from. I casted to character from construck and promoted as variable and named it char ref. Ive done this with no issues several times before but for some reason its not working now.

Yeah, i had this too (4.15), should work when you make the cast from the function (temp fix) …

i have the cast in the function but that doesnt work either.

The GetText0 variable is bind to a text field?

Yes its bound to a text. i even tried deleting the variable and remaking. Also using a different variable none of then are showing the value on the screen. It stays at 0.

Same problem. Hoping this to be fix

Could you post the code where you’re setting it on construct? Also, are you setting it before the pawn even exists yet? Remember that there is an order of code execution, and if you’re creating the widget before the pawn is even in existence, you could be setting Char Ref to a nullptr.

Another portion to check would be where you attempted to use a cast instead of a variable reference. Is that cast failing, or succeeding? I would add a print string after the cast failed to double check.

Might I suggest looking into handling this on posession of pawn. Having pawn cast to the incoming controller to execute the creation of the HUD.

This will help insure everything exists before loading.

On poses can be overridden on character class

Here is the construct. But im doing a normal cast in the function like the picture above right now.

You would want to use an “IsValid” node on your references. And also that one picture where you cast inside of the binding: You can’t use the same return node for the CastFailed.
That will try to access the return value of the cast node which is empty on failed cast. Copy paste the Return node and just use that for the CastFailed.

In general there are like 2-3 approaches to this:

#1: Make the Reference variable “Edit” and “Expose on Spawn” and pass the reference of the character when your create the widget. This usually makes sense if you create the widget inside of the character or right after you created the character.
So you have a reference of some sort that you can pass.

#2: Get PlayerCharacter0 and cast on EventConstruct: That needs you to be sure that the PlayerCharacter is actually already spawned and possessed, otherwise this will be null.

#3: Getting the PlayerCharacter0 in the binding itself and using IsValid on it. Casting it there and connecting everything that does not result in actually VALID and successful casting to an empty return node.
This version is the laziest though. You should avoid it and rather try to get one of the other two working.

Ok, i figured out the problem. I use just the camera for my game and i was testing angles with a normal camera before i put it into the character. i have that camera on auto posses. So the player character didnt spawn at all. My mistake sorry for all this for no reason :(.