I am working on a local two players game like what the video shows. I want to implement the function to restart the game once any of the two players win the match. The following images show what I currently did with blueprint. It didn’t quite work as what I expected. Like the last image shows, the two players didn’t spawn properly. Did I use "restart game " in a wrong way? Or is it because my game is a two players game? Basically all I want is to put everything back just like the game just starts. Do I have to manually reset all objects position to its original ones in order to implement “restart”? Thanks.
Well, you can destroy this two players, spawn two new ones and possess them by their player controllers. Or “reset” them manually, which means reset their score, health, teleport them to some start locations and so on…
Currently my second blue print is in widget’s blue print where I display that two buttons. Do you mean I should put them in game mode’s blue print? If yes, how can I do that? Also, Currently with Restart Game, what I will get is what the last picture shows, it seems like players didn’t spawn properly, you can see nothing from the camera, although everything is fine when the level was loaded for the first time.
That’s also what I am thinking if I can figure out a better way to do this. But do you know whether there is any way to use Reset Level or Restart Game provided by Unreal?
Are your values inside GameMode? because RestartLevel I believe will only reset values [variables?] in GameMode bp… Just make a test, create a var with value 0 in gamemode, when game starts set it to 1, and when a player wins, after the reset level, try printing the variable and see if its 0.
One thing I just realized is that I can’t link “get game mode” to “restart game”. It seems like that “get game mode” returns “game mode base” that is not the same as “game mode”. I watch tutorials online, people can simply link those two things together. So I guess Unreal was changed over the time.
One thing I just realized is that I can’t link “get game mode” to “restart game”. It seems like that “get game mode” returns “game mode base” that is not the same as “game mode”. I watch tutorials online, people can simply link those two things together. So I guess Unreal was changed over the time.
It seems like cast will always fail in run time. I print text after “restart game”, text is never printed. Instead if I link “print text” to “Cast Failed”, text will be printed.
Instead casting to GameMode try casting to VehicleAdvGameMode and see if you can access Restart Game. If that doesn’t happen just create a Execute Console Command node with the RestartLevel command. Another alternative is getting the player controller and running the RestartLevel function.
VehicleAdvGameMode is considered as game mode base instead of game mode, so I can’t link it to restart game. I used ResetLevel above, so last picture shows that it didn’t work properly. The two players are not generated.