Haxe - How to Restart Level

Hi,
For the prototype I’m making, I want to restart the game/level (the prototype only has one level) when the player dies. How can I accomplish this with the Haxe scripting language?

1 Like

Like respawning or restarting full level alltogether?

If just respawning, then when you die switch to another camera(blank screen would not appear), and destroy the player, and the spawn the player in position you want and then switch the camera back to it, while doing this swithcing remember to lock the control so that player dont move or do anything, b/c this might give bunch of errors.

Dunno much about restarting whole level but i got idea, you can create json file where it is filled with level detail and when restarting the level destroy all thing in levels and the import all detail about level from previously created json file and spawn objects based on it.(I might be terribly wrong about this, but better leave something here than nothing).

2 Likes

Thanks, but isn’t there a built-in function in Armory 3D for restarting/reloading a scene/level? Actually, how do we load scenes in Armory using Haxe?

Armory needs something like that :
Scene.current.Release()
Scene.LoadingScreen.Load(“filename”)
Scene.current.Load(“fileName”)
Scene.LoadingScreen.Release()

To unload current whole scene, load a new one and play a loading screen when scenes are too long to load.

1 Like

A quick work-around could be to have two scenes, the game scene and a blank scene, and when the player dies use iron.Scene.setActive() to switch to the blank scene, and then back again to the game scene.

Something like this untested example:

iron.Scene.setActive("BlankScene",
    function (object) { iron.Scene.setActive("GameScene"); });
3 Likes

Thank you! Your code worked right off the bat, but only once. The second time the player loses the screen just turns black (but without errors in the console). Any idea?

Use the Api to keep only one scene, Armory does not support additive scenes.

  1. Remove(“gameLevel”) to remove the actual scene and it’s states
  2. Create(“gameLevel”) to re start the same scene
1 Like

MagicLord

1h

Use the Api to keep only one scene, Armory does not support additive scenes.

To the best of my knowledge that is not true. You can load a scene from blender into another scene. For example if you have your character is a separate scene in your blend file, you can load that into your level scene in Armory using Spawn Scene.

3 Likes

I don’t know right off. Are you fine sharing your blend?

1 Like

I’m not on my computer right now but tomorrow I will share it.

1 Like

You mean additive scenes is supported ?
For example a base level is a scene, and the other scene would be enemies and items placed at some places on the base level.
Can you set active two scenes at same time to get it work ?

No, that isn’t how it works, I think maybe we are not understanding what you mean by additive scenes. It sounds like you mean scenes that stack on top of each-other similar to Blender layers, is that right? It doesn’t do that exactly, but it does let you spawn other scenes into the active one with a spawnScene() function. There can still only be one active scene at a time, though.

1 Like

I don’t know if they have same functionality.
https://docs.unity3d.com/ScriptReference/Application.LoadLevelAdditive.html

Here is my blend file.
jogo23.blend (4.0 MB)

Oh, :man_facepalming: I guess if you are using Haxe traits I need a zip with the code and the blend. :smile:

Unfortunately this forum doesn’t allow zip file attachments. So I just posted all assets here:

Also, I posted the current version of the game in Itch.io:
Super Chicken by AlexFerrart3D

Moved …