Unexpected loop at event begin play

Do you got “HUD” blueprint? MyCharacter is null there for some moment, how do you set it up?

Hi everyone!,

I’ve been following [this][1] oficial tutorial but it has some kind of error in which it seems there are cyclic calls and I can’t figure how to solve it. The steps could be as follows if I’m right:

  1. Scene is created

  2. A screen is added with a menu on top, showing the mouse pointer and blocking (in theory) the current scene.

  3. Every button works as expected except Play Game button, which creates a new scene.

  4. The new scene, at the moment it’s created, launches the main menu again, so first screen never stops to being shown and the game never can be played.

When I quit the game, console shows hundreds (or thousands) of errors, depending on number of times I’ve pressed on “Play Game” button.

I’ve checked errors showed at console, but they lead me to a piece of code that works alright if I Main Menu is not shown at start, so I think this could be a colateral failure (some kind of null access to a variable that is being resetted somewhere in program’s flow.

I attach some images to show the problem:

I don’t know how to solve this or what nodes are appropiate for this purpose.
Any help is appreciated.

Yep

HUD template is working as expected: progress bars are getting updated when jumping (if you saw the tutorial) and by pressing F, ammo is getting down as it should and character is not shotting if ammo == 0. So everything at the HUD is working fine

Can we have a screenshot of the HUD blueprint itself? It seems as if the editor is saying that there is an access violation in the blueprint, so being able to see the nodes themselves would be helpful.

Sure!

Here it is: 2 functions binded to a couple of text (ammo and maxAmmo respectevely) and graph of HUD editor creation.

Thank you so much for your answers :slight_smile:

I would say that MyCharacter, being a child of current scene, when that scene is deleted, character is deleted as well and that throws that error (like it would have lost the reference to the object – Pointer to null). But as I said, HUD works fine without menu screen. No error rising… So that’s why I’m not paying much attention to this console output :frowning:

Hi ,

The reason that this is looping is that you’re creating this widget using OnBeginPlay. OnBeginPlay is run every time the level is loaded. The best way to get around this is to load a different level in your ‘Open Level’ node. If you do wish to stay on the same level however, you can just skip that node entirely so that it doesn’t run OnBeginPlay again.

Have a nice day,

Hi , if you don’t mind, please could you explain a bit more deeply

“… you can just skip that node entirely so that it doesn’t run OnBeginPlay again”.

You can see I’m not so good at english and I’m not getting what you mean with that :-S
Thank you for your time,

Whenever ‘Open Level’ is run, the ‘OnBeginPlay’ event for that level is triggered. Every time your ‘Open Level’ node is run, it is opening the same level again which causes the same ‘OnBeginPlay’ to be run. This causes the widget to be spawned again and causes your infinite loop.

Hi , thank you for your responses, you are very kind :slight_smile:

Anyway, I would like to know a proper way to solve this (show and hide a menu screen which pauses the game and show that screen at the beginning of the application). I knew already what was going on (you can see the tittle of the post :wink: ). I traced and show the messages but if I want to create a pause menu, “Play Game” or “Resume Game”, I’m going to have same problem.

Maybe someone knows a working tutorial to do this (this one is working no more, at least on 4.7, because the reasons we have discussed in this post).

Any URL or graph editor screenshot is very appreciated :slight_smile:
Thank you for your time
Best regards,

Thank you so much ,

I’ll take a look to “Set Game Paused”. Thank you too for considering to edit that tutorial. I’m finding so many oficial tutorials which needs editing (at the moment, everyone I have tried with C++ code needs some fixing, in most cases, a simple text note on the video will do the job :wink: )

Best regards,

I suposed so, but because of the video showed on corresponding lesson (in which there wasn’t a second level still) it worked as it should, so I though it could be caused by some kind of main loop updating between versions. Seems to be just a little missunderstanding and at that point, program shouldn’t work properly :slight_smile:

If you remove the OpenLevel node, it’ll stop the infinite loop. Instead of opening the level again to open the widget, you can simply create the widget again in another function which is bound to your pause button using the Create Widget and Add to Viewport nodes.

If you would like this to be a pause menu that you can use during gameplay, you can also use ‘Set Game Paused’ to pause and unpause the game. This disables all input for everything except for widgets, so it is perfect for a pause menu.

It seems as though the documentation can be misleading, but it does work. The issue you’re having is that you’re only using one level. In the tutorial, they have you make a second level called “Main” and place the nodes for creating the main menu widget in the Level Blueprint for that level. When hitting Play Game, the OpenLevel node opens the “FirstPersonExample” map instead of opening the same one. This would avoid causing the loop.

If you watch the World Outliner during the video, the first entry in the World Outliner is the current map. It is displayed as ‘Main’ until the user hits ‘Play Game’ at which time it changes to ‘FirstPersonExample’.