Accessed none error?

I was creating a HUD that displayed the ammo and followedthis guide exactly and now I’m getting an “accessed none” error during runtime.

They read “Blueprint Runtime Error: Accessed None trying to read property MyCharacter from function: ‘GetCurrentAmmo’ from node: Return Node in graph: GetCurrentAmmo in object: HUD with description: Accessed None trying to read property MyCharacter” and “Blueprint Runtime Error: Accessed None trying to read property MyCharacter from function: ‘GetMaxAmmo’ from node: Return Node in graph: GetMaxAmmo in object: HUD with description: Accessed None trying to read property MyCharacter”.

What is an “accessed none” error? Everything works as expected, so should I change anything? Do I need unreal’s version of a try catch block or something? If you need pictures of my code, they are identical to the pictures in the guide.

Hi,

“Access none” errors are caused when you try to access something from a null variable or accessing a variable that doesn’t exist. In your case, probably you didn’t compile your character blueprint after you added the CurrentAmmo and MaxAmmo variables to it. Since it’s not compiled, your HUD doesn’t yet see the updated version and thinks those variables don’t exist! Simply recompile your character blueprint first and then the HUD blueprint.

Hope this helps.

Thank you for the explanation! Knowing that “accessed none” is the same as “null pointer,” I was able to do a little diagnosis myself. Compiling the character blueprint and then the HUD blueprint didn’t fix it, but I added a delay before I added the HUD to the viewport and it made the two errors come after play started instead of before. I thought that it may be trying to get “Ammo” and “MaxAmmo” from the character reference variable before it was initialized on construction, but charging the variable to “GetPlayerCharacter–>CastToFirstPersonCharacter” didn’t get rid of the error either.

Is there any downside to leaving these two errors be? Each of them only occur only once before play begins and everything works as intended.

It’s kinda weird that you’re getting warning yet everything works fine. I did this exact same tutorial some time ago and I didn’t get any kinda error whatsoever! HUD is constructed and added to the viewport by the player in BeginPlay node (i.e. when the player is already fully constructed), so there must not be a need for any delay node!

I had the same errors in my project. Just add an Isvalid to check your reference before you try to read any variables from it. In my case the error disappeared.

1 Like

That worked. thanks