Accessed none trying to read property

Hello everyone,

I’m trying to figure out something than i can’t fix right now. Let me explain my problem with some screenshots.

This first solution is working, i don’t run any error when i hit play and stop. Except this blue note.

But when i try to fix this blue note by doing this :

I run into this error :

I even tried to cast it into my reference casts here (after setting controller ref) :

But it’s not working, i run into the same error no matter what.

Maybe do i misunderstand something ? Or maybe i’m doing something wrong but can someone please help me ?

Thank you in advance and have a good day !

Hi, you need to get an object of type GameTime_HUD and set your GameTimeHudRef with that. If you never set your GameTimeHudRef, then it will be a nullptr.

So in your first image you’re trying to cast nullptr to GameTime_HUD which will fail, so it will execute CastFailed and therefore never executing any of the logic you currently have beyond the cast.

In your second image you’re trying to access TimeUTC from a nullptr which will throw an error (in C++ it would crash the game).

So you need a valid actor that is of type GameTime_HUD and set your reference with that. So if you’ve set GameTime_HUD as HUD Class in your world settings, then you can access it via GetPlayerController -> GetHUD -> CastTo GameTime_HUD. Here you need to cast since GetHUD will only return an object that is of type HUD (even if it is a GameTime_HUD), not of GameTime_HUD. But since it is a GameTime_HUD casting will succeed and you can access its functionality.

If GameTime_HUD is just some widget / object, then get the reference from where you’re spawning it.

Hello chrudimer, thank you so much for your clear explanation ! GameTime_HUD is a widget.

By doing this, it works perfectly :

But when i cast it first into “Reference casts”, and then when i pin my GameTimeHUDRef directly to TimeUTC, i have still the same error. It’s not a major problem but for clarity, it would be perfect to set it in “Reference catsts” haha

Thank you anyway, it was very helpful.

Try printing something after CastFailed. I’ve never tried to cast an interface to something, didn’t even know such a thing existed =)

But my guess would be that the cast will again fail, since the interface is not a GameTimeHUD.

If it is a widget, then were you create it, save a reference to it into a variable so that you can later access functionality from it.

If you create an object reference variable, then it is just a reference to an object, it is not the object itself. What casting does is, it takes an object reference as input and tries to cast it to the type that you specify (lets assume you try to cast it to class X). If that object reference that you input there points to an object that is of the type X, then the cast will succeed and you can access all the functionality of X. If it is not of type X, then the cast will fail.

I’m curious too. Why are you casting a blueprint interface? A little confused as to what your trying to accomplish. Do you need a reference to the interface? That is hooked up in the Class Defaults.