How to get the same effect from a level BP to a Widget BP (reset button)

I am somewhat close/on the right track to getting what I was aiming for. Basically user clicks on a button, it resets the level. The only issue is, the way I have it setup currently is, the game restarts the level fine but it doesn’t keep the same mouse camera movement. I am just needing a bit of help on what nodes I am missing to basically reset the level as if playing the level for the first time.

This is my Level BP, if the user presses R it resets and does exactly what I want it to.

The problem is I can add all the same nodes and such to a widget BP but the Playerstart As I have a trigger point that will pull up a menu that gives the player a few options in this case I am trying to get the retry button to be just like the Level BP.


I currently have this and I somewhat understand why it’s wrong and doesn’t 100% work how I want it to, I believe it will need another node of some sort I’m just unsure what node I need to be able to correct it (or a node that is able to read the playerstart so I can plug that into “start spot”.

Hopefully I made sense, please let me know if you need anything else that may help out.
(I am using third person template to build my project).

In LevelBP you have the ability to reference a specific PlayerStart from the level, because LevelBP is part of the Level.

You have to keep in mind that, other classes such as PlayerController, GameMode, Character, Widgets, etc… are all level-agnostic. They can (and should) be reused in many levels and as such it’s not right to hard-code a reference to a specific actor from a specific level in one of those classes.

If there is only one PlayerStart per level, then it’s pretty simple, you can retrieve it using “GetActorOfClass” which will return the first instance found of specified class (PlayerStart).

If you have multiple PlayerStarts, how do you determine which one to restart to ?
There are several options. Two of them I can think of right now :

  • Give a tag to the “main” playerstart (the one you should reset to). Then you can use node “GetAllActorsOfClassWithTag” to retrieve the playerstart with desired tag. If you have multiple levels make sure to give the tag to one playerstart in each level.

  • Create a new BP actor class that you are going to use as a singleton to bridge the gap between game code and level objects. In that BP you can add any number of actor reference variables (make sure you tick “Instance Editable” for the variables). For example add a PlayerStart reference variable. Then make sure you place one of these actors in each level, and fill the variables in the detail panel to point to level actors. Then from game classes (eg. widget), you can use GetActorOfClass to retrieve your “singleton” actor and access all its variables.

1 Like

Thank you very much, that explains alot I knew I wasn’t able to, just didn’t know “why” I couldn’t. So thank you. I only have one playerstart yes I gave it a go and it restarts, but it doesn’t seem to take me back to where the player is (and not sure if the player is there as it basically looks like it just closes down the “win screen” widget and the camera cannot move (edit: I was able to spin around before hitting the trigger to activate the win screen, when I hit retry the game restarts but there is no character where there is meant to be one). This is the updated BP, have I plugged something in wrong (or a lack of plugging something else in)? I have selected the character in the actor class and plugged in the return value to the start point.

Sorry if I’ve muddled up I was thinking basically comparing it to the level BP that instead of “Playerstart” in this case it would be “Get Actor Of Class”?

Seems about right.
Gonna need more details, what exactly is happening ? Got a video ?

I can think of many things but not sure what state your game is in when it happens, like: is it in post-match state ? does your controller still possess a pawn ? is game paused ? is mouse cursor still active ? do you get any relevant logs ?

2 Likes

Here is a video showing what happens, I did a full screen capture so hopefully anything that is helpful you can see. (depending when you see the video, it says its processing into HD in about 36 mins or so from the time of this post, so hopefully it’s done).

From what I can tell from those questions, no the game isn’t paused (as far as I can tell), I can click but cannot move camera not keep it in the game mode, like if I’m hitting shift+f1 but I’m not), no error logs. Perhaps the controller isn’t possessing the pawn.

I hope the video serves as some usefulness. Sorry for the late replies.

Can you try what happens with just “Restart Player” instead of “Restart Player at Player Start” ?

1 Like

You’re a star buddy! Thank you so much, thats what fixed it. Massive thanks!

If anyone comes by and is new and isn’t fully sure. Here is the updated BP

Well then in this case it most likely means your call to GetActorOfClass returned nothing.

image

What is this bacon box thing ? Is this is where player should respawn ? Is there one in the level ?
Try changing the class to PlayerStart and hopefully it should also work this way.
If there is only one player start in the level this is not even required though, the simpler node “Restart Player” will find the one player start automatically.

1 Like

That’s just the character that is attached to the playerstart. I only have 1 character at the moment and I do plan on having more than 1 so I will need to update this BP in the future but for now, it works with the one character (I’m half way through multiple characters but I ran into another issue but will work on that at another time).

Or just a question, if I leave the actor class blank would that in theory work for any character that hits this trigger?

The value you plug into StartSpot should be the PlayerStart, not the character.

The character is destroyed when calling ResetLevel so that’s why it returns nothing, and then RestartPlayerAtPlayerStart fails because you send nothing as StartSpot.

1 Like

Ahhhh yes I see, that makes sense. Thank you. I fixed that up. But I’ve just noticed it loses its default movement of the mouse (where you can move the mouse around freely without needing to click) how the third person template mouse movement acts (this one I believe)

This only happens after I’ve clicked on the replay and it loads back into the game. I have a custom mouse mapping to another function (you can zoom in and out with mousewheel) and that still works, just not this default unedited Camera input

That’s because your mouse cursor is still active, isn’t it ?

When showing the menu you are activating mouse cursor. You need to disable it when closing menu. Set input mode game only or something like that.

1 Like

Ah yes makes sense and that fixed it. Thank you!

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