Unreal C++ 2D course - BP Button error

Hi,
I’m at the video 4.40 of the 2D C++ unreal course, and I’m geting an error when I press the Play Again button.

This button should launch the Restart function. This function works correctly when the player die.

This is the BP:

This is the error code I’m getting when I press the button:
Blueprint Runtime Error: "Accessed: None trying to read property MyGameInstance". Node: Restart Game Graph: EventGraph Function: Execute Ubergraph Widget BP Win Screen Blueprint: WidgetBP_WinScreen

I hope someone can help me with that :slight_smile:
Thanks

If I didn’t know any better, I’d say the game instance is not initialised.

I would suggest adding rhe is valid check on the game instance and then add a print to each of the valid and invalid paths. This will tell you if the variable is valid or not… I would suspect not. This shouldn’t get uninitialised however.

One possibility is the cast is failing.

The best place to post this is in the Q&A for the course against the lecture.

Thanks, I’ll give it a try tomorrow!

I posted here cause my question is not posted in the lecture. Like, nothing happen at all when I press the button to post the question. Tried different browsers with/without inconito mode.

Did you try paste in an image? Instead you need to insert and browse to the file on your computer

1 Like

Thanks for the tip, I was able to post it in the lecture directly :smiley:

I added a “is valid” on the “MyGameInstance” with two prints (one if valid, one if not) and I’m getting the not valid print when I press the button.

That means the cast is failing which is why you’re seeing the error you are seeing. Did you set the default game instance class in project settings to the correct class?

1 Like

Thanks Beegeedee!

In the project settings, I had the c++ class selected instead of the BP game instance. Now it’s working :smiley:

1 Like

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

Privacy & Terms