Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Making a level "half-reset"?

Discussion in 'Scripting' started by LeytonViner, May 10, 2022.

  1. LeytonViner

    LeytonViner

    Joined:
    Apr 7, 2017
    Posts:
    151
    I'm making a FPS roguelike, and when my player kills all enemies in a room I make a checkpoint where he is. When the player gets killed, I respawn him there and clear up all the mess he made before he died. Issue is, I can't really bring back any enemies he killed because, well, they're dead. I can't reload the scene, because the levels are random. How can I do this?
     
  2. frankiwinnie

    frankiwinnie

    Joined:
    Dec 1, 2020
    Posts:
    26
    I am not an expert but your question reminded me the command design pattern. As I read from sources and from the videos that I watched, the major use of command design pattern is to undo the actions held in the scene. You can check on that from youtube videos, maybe it will solve your problem to implement that pattern.
     
  3. LeytonViner

    LeytonViner

    Joined:
    Apr 7, 2017
    Posts:
    151
    Maybe, it sounds quite hefty to do though. I'm sorta looking for something like in Hotline Miami, but instead of the floor resetting, it's just your progress IN the floor up to your checkpoint
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,710
    Here's one approach:

    - when you make all the enemies for a level, put the GameObject references into a list
    - now go and SetActive(false); all of them. These enemies will NEVER attack the player or even play in the game. They are "hot-swap templates" waiting to make fresh enemies.

    - when you start the level (OR restart the level):

    --> iterate the list of hot-swap disabled enemies:
    -----> Clone it with Instantiate<T>() and its position / rotation
    -----> SetActive(true) the clone
    -----> put the clone in a list to destroy when the player dies
     
  5. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,589
    There are no truly random numbers in a computer. If your levels are random, nothing stops you from generating the exact same level twice using the same seed. Generally speaking it would be possible to simply reload the scene / level. Whether that is the easiest solution for your situation depends on what exactly you are doing.
     
  6. LeytonViner

    LeytonViner

    Joined:
    Apr 7, 2017
    Posts:
    151
    This is stupidly simple I love it. Thank you so much dude
     
    Kurt-Dekker likes this.
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,710
    Suits me because I'm stupidly simple too!

    Is this for your procgenned office building layout? It seems such a system would be perfect for that style of procgen game.

    If you want to have certain minibosses that REALLY get killed and don't resurrect, just have them additionally Destroy() their original template enemy, and then you'll only have to kill those guys once, but everybody else respawns.
     
  8. LeytonViner

    LeytonViner

    Joined:
    Apr 7, 2017
    Posts:
    151
    yeah sorta, i dropped the procedural office because it was hard to do and went with prefabs. But yeah enemies don't come back ever so destroying their source would be a good idea