Unsure why my cast is failing

Basically, my game involves a component where The user clicks a button on a UI widget, which prompts the game to check whether a certain task has been completed, in this case, taking the bins out.

The “Bin” actor is simply set up so that, when interacted with, checks if the bins have already been moved, and if not, the bin moves in the world, and sets the “AreBinsOut?” variable to true. I know it’s being set succesfully because the interaction works as intended, and does not complete.

So, in my UI Widget, when the player clicks on this specific button, I want it to check the value of the “AreBinsOut?” variable, and return a different message depending on whether it is true or false. So, I create a custom event, and cast to bin, and ask it to read the Are Bins Out variable. However, the cast is failing every time, with the log providing the following error:

“Blueprint Runtime Error: “Accessed None trying to read property K2Node_DynamicCast_AsBin”. Node: Branch Graph: EventGraph Function: Execute Ubergraph Message Screen Mum Blueprint: MessageScreenMum”

(Note: MessageScreenMum is the name of the widget with this interaction happening)

I’ve read a whole bunch of documentation and watched videos explaining casting, and I still don’t understand what is happening here. The “Bin Reference” variable is set to an Actor Object Reference, and it knows that the Are Bins Out variable is an option, but it’s just failing every time?

Even if I add a variable that has a direct reference to the Bin object, like in the below picture, the value is always returned as false, even if the AreBinsOut value is set to true.

I’m just so confused at this point, any help would be greatly appreciated!

perhap Interface would work better

1 Like

Where are you setting the variable bin reference?

Have you set the bin reference variable to public and set it to an instance of an actor in the world?

Are you using get actor of class to set it?

If it has no value (a null pointer) then the cast will always fail because the variable is empty.

1 Like

Are you using get actor of class to set it?

OK this was the part that was missing, i added that and it now does the cast correctly and returns the value as it should!

and set it to an instance of an actor in the world?

this part still confuses me however, I didn’t realise that was even something I could do lol. Is there a certain node I could use to do that easily?

Just change the eye icon next to the variable (to it’s right side) to open and then the variable will show up in the actors details panel. Once placed into the world you can use the eyedropper or dropdown next to the variable to set it to an instance of the actor in the world.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.