Accessed None from Node

Hi,

I know there are similar questions in the AnswerHub but they seem to be specific and I cant for the life of me work this one out. I have a UMG for the Player HUD. When the player goes underwater I have a trigger that sets the character as ‘underwater’ and calls a progress bar in the HUD to become active. This progress Bar indicates the amount of air the player has left and counts down. When the player surfaces this refills again.

The script works fine except when I exit Play In Editor I get the following error messages. I get one message for each time I reenter/exit the trigger. Some forums have suggested using a IsValid node. I do not know how this works.

Can anyone show me how to get rid of the errors - I am not sure why it is occuring and when I am referencing a component of the widget.

Any help is greatly appreciated.
Thanks
Ben

That blue Note you have inside the GetPercent_0 function, is because in the case the Cast To Player1 fails (GetPlayerCharacter’s return value is not of type Player1) the function doen’t get to the ReturnNode. Create a Local Variable of type float to hold the Air (local to the function). Give it a default value that you want to return when the CastFails. Then set it to the Player1’s Air value when the Cast succeeds. Connect both the Cast Failed and the Set node to the ReturnNode. Then connect the Local float variable to the Return Value of the ReturnNode.

The Accessed None error is very common, it means that somewhere you used the Player1HUD variable when it was empty (None, NULL, nullptr, etc). I can’t see where are you calling the Underwater event and how everything works in your project, so I would suggest you look at all the places where you are using the Player1HUD variable and add a IsValid node before you use Player1HUD. The IsValid node check if the variable is empty or not. It has two output pins, one if it valid and another when it’s not valid.

I would add an IsValid node in that Underwater Event for example, before the Branch node. Or after the branch on both cases: when IsUnderwater it’s true and when it’s false.

You can also place breakpoints on certain nodes to make the game stop when it calls that node, and check the Player1HUD variable’s value while it’s stopped.

Thank you so much Ghar - the IsValid node before the Branch node on my Underwater Event fixed it.