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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Deleting Objects permanently

Discussion in '2D' started by LucaBGT, Oct 21, 2015.

  1. LucaBGT

    LucaBGT

    Joined:
    Feb 20, 2015
    Posts:
    22
    Hello everybody!

    I have al little problem with my mobile 2D Platformer.

    The game setup is the following:

    A player is initialized in the first scene, a little in game cutscene is started.
    When it's finished, the player is allowed to exit to the left into another scene
    (similar to DuckTales game in-level-transitions).
    I gave the player a "DontDestroyOnLoad"-Script, and it worked well.

    However, when coming back to that first scene, the camera freaked out and the UI-Buttons where nowhere to be seen. I think this was because the camera was searching for a GameObject with the "player" tag, but loading that first scene loaded another player and the cutscene player again, even though I gave it a script which made a public static boolean called destroyed, and if that bool was true, the cutscene would have been destroyed, otherwise the cutscene would run, set the bool to true for the next loading and delete the cutscene (with Destroy(this.GameObject)).

    In the end, I think I could fix the player problem myself after some trial and error (I thought maybe loading the player scene once and when the player tries to enter the scene again, the game leads the player to an exact copy of the scene without the player initializing), but I have no idea how to solve this cutscene problem, which will ruin my whole project if I can't fix it.

    Please help!

    Thanks in advance,
    Luca
     
  2. VorpalSilence

    VorpalSilence

    Joined:
    Oct 22, 2015
    Posts:
    13
    Given the solution that you mentioned around loading a copy of the first scene that has no player initializing on it when returning to that scene, are you not able to also remove the cutscene itself from the copy?
     
  3. LucaBGT

    LucaBGT

    Joined:
    Feb 20, 2015
    Posts:
    22
    Yes, but I want to have cutscenes in more than just one scene, and after a while it would get really confusing with duplicating all the scenes. Any ideas?
    Thanks again!
     
  4. VorpalSilence

    VorpalSilence

    Joined:
    Oct 22, 2015
    Posts:
    13
    You could perhaps decouple your cutscene logic from the scenes themselves and also give that the don't destroy on load script. Then just run certain cutscenes based on player position, current level loaded and other similar information as needed.
     
    theANMATOR2b likes this.
  5. LucaBGT

    LucaBGT

    Joined:
    Feb 20, 2015
    Posts:
    22
    Thanks, I will try to do so.