Casting to widget and setting node, getting error

Hi, could you help me? I seem to be getting a ton of errors saying "Blueprint Runtime Error: “Accessed None trying to read property K2Node_DynamicCast_AsPlayer_HUD”. Blueprint: Button Function: Execute Ubergraph Button Graph: EventGraph Node: Set KeyTimeDown
"

This is the “Button”

This is the “Button”

This is the “Button”

I still get the errors even after the delay.

Where is the blueprint “Button”? That is where the error is. I need to see that blueprint not the player HUD.

Ahh I see now, my bad. You had everything blacked out except the player HUD so it looked like that’s what we were being shown. So what is before all of this in the execution path? Tick fires off pretty early so if the widget isn’t initialized yet you will get errors. See what happens if you put a delay after event tick for like 2 seconds. See if the error shows up.

My bet, “Tick” is firing before you get to the cast node so it is trying to pull data that doesn’t exist yet.

What is before this in the execution path. I need to be able to see how you get to that cast node from the start. Can you copy the blueprint nodes and paste them here https://blueprintue.com that way I can scroll around and see what the issue is easier.

You can’t use an overlap like that. That means you wait until something “overlaps” something to cast to the player HUD and get the reference. Meanwhile TICK is going like crazy trying to set the “Key Time Down” variable inside a null reference. This setup will never work.

Honestly, the real issue here is why you are using tick in the first place. Tick isn’t the best thing for this as you can see. It would be easy to use “on begin play” to create a reference to the widget immediately instead of waiting for an overlap but even then Tick will still have fired off many times before begin play creates that reference causing errors. You need to stop using tick for this and try a timer or some other means for whatever you want to do. Tick is always going to give you an “accessed none” error because no variable can be initialized faster than Tick is going to execute.

Or have a gate after tick and only open it after the reference is created with the cast node.

It doesn’t make sense. You can’t set something that doesn’t exist yet. You have an overlap event which means you are “waiting” for something to happen during your game and THEN you do XYZ. Or do like I said

On Begin Play → Get User Widget Object → Cast To Player HUD → Save Output As Variable → Open Gate for tick to execute.

Remove the cast node from the overlap event sequence and hook everything back together.

Is your cast node failing?!? Print a string from the “Fail” output.

Well that’s your problem! Did you set the widget in the details panel to be of type “Player HUD”?

so what do I do?

I’m trying to make a button that will show up when I enter the box collision of the “Button” then you have to hold it down and it will play a matinee sequence

I need to set this every second to update my widget

I’m trying to make a button that will show up when I enter the box collision of the “Button” then you have to hold it down and it will play a matinee sequence