Few scene change questions

Announcements, support questions, and discussion for the Dialogue System.
Brijac
Posts: 18
Joined: Sat Apr 25, 2020 5:40 pm

Re: Few scene change questions

Post by Brijac »

Hello again, I have one more question about this:
Brijac wrote: Thu Apr 30, 2020 8:40 pm I have Lvl1 and Lvl2 and it works great when I change scenes with Scene Portal when Player triggers it but I would to put something like IntroLvl2 scene between Lvl1 and Lvl2. Player would trigger Scene Portal on Lvl1, IntroLvl2 would load with text story about Lvl2 and then there would be a button to Start Lvl2. The problem is that Scene Portal can't work on button (probably can with editing the script but I'm not really good with C#), it works only when Player triggers it so my question is how could I transfer my Player to a specific Spawnpoint (just like Scene Portal does it) on Lvl2 with a Button on IntroLvl2 scene?
This works fine like you instructed me before but when I change the scene from Lvl1 to intro scene, the player, player controller, third person camera... everything transfers from Lvl1 to intro and the player is falling behind the background of that intro scene and you can even hear some audios playing if you press the buttons. So my question is, is there any way I can disable that don't destroy on load (for player, player controller, dialogue system...) while I'm switching from Lvl1 to intro but still transfer those objects to Lvl2 scene? The scenes go like this: Lvl1(has player, player controller, dialogue system...) -> intro scene(should not have player, player controller, dialogue system...) -> Lvl2 (should have player, player controller, dialogue system from Lvl1...) Lvl2 has to have everything from Lvl1 because there is inventory and the items should transfer between scenes.

Or maybe set those objects inactive when the intro scene loads but when I press the button to start the Lvl2 then set them active somehow?

I also asked about the Menu Framework here: https://www.pixelcrushers.com/phpbb/vie ... f=3&t=3127
And this problem also happens when I start the game with this menu and I press quit to main menu, the player, dialogue system and everything that is set to dont destroy on load goes to mainmenu scene.

And one question about the death in game and menu. Currently, when the Player dies he just respawns because I use Invector. Do you know is it possible to maybe display loadgamepanel when the death happens or maybe load last saved game automatically? I have this On Dead Trigger so maybe I can use that: https://i.gyazo.com/f6a234bb39b85ebfdc2 ... 0ecf08.png
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Few scene change questions

Post by Tony Li »

Please set up your Invector player and inventory UI according to the instructions here: Invector Integration. In particular, see the Saving, Loading & Scene Changes section at the bottom of the page. Make sure to untick Use Instance on both.
Brijac wrote: Thu May 07, 2020 3:58 pmAnd one question about the death in game and menu. Currently, when the Player dies he just respawns because I use Invector. Do you know is it possible to maybe display loadgamepanel when the death happens or maybe load last saved game automatically? I have this On Dead Trigger so maybe I can use that: https://i.gyazo.com/f6a234bb39b85ebfdc2 ... 0ecf08.png
You'll have to modify Invector's vGameController.cs script. Its OnCharacterDead method is hard-coded to respawn the player. Comment all that code out, and open the menu framework's load game panel instead. Or load the last checkpoint save. Or add a new panel that's a copy of the load game panel but with a "return to main menu" button added.
Brijac
Posts: 18
Joined: Sat Apr 25, 2020 5:40 pm

Re: Few scene change questions

Post by Brijac »

Tony Li wrote: Thu May 07, 2020 5:23 pm Please set up your Invector player and inventory UI according to the instructions here: Invector Integration. In particular, see the Saving, Loading & Scene Changes section at the bottom of the page. Make sure to untick Use Instance on both.
I did set up the Invector and Dialogue System with those instructions but that Use Instance was not in Grounded section (they changed it I guess) and it worked without it (my player was transferred between the scenes) so I never really bothered with it. If you want to know (for some future questions maybe) I found that Use Instance in Debug section of Player controller. This way I only have to put a prefab of a player on ever level I want to use him. Thanks again.
Tony Li wrote: Thu May 07, 2020 5:23 pm You'll have to modify Invector's vGameController.cs script. Its OnCharacterDead method is hard-coded to respawn the player. Comment all that code out, and open the menu framework's load game panel instead. Or load the last checkpoint save. Or add a new panel that's a copy of the load game panel but with a "return to main menu" button added.
I will try this. Thank you :)
Brijac
Posts: 18
Joined: Sat Apr 25, 2020 5:40 pm

Re: Few scene change questions

Post by Brijac »

Brijac wrote: Fri May 08, 2020 4:57 am I did set up the Invector and Dialogue System with those instructions but that Use Instance was not in Grounded section (they changed it I guess) and it worked without it (my player was transferred between the scenes) so I never really bothered with it. If you want to know (for some future questions maybe) I found that Use Instance in Debug section of Player controller. This way I only have to put a prefab of a player on ever level I want to use him. Thanks again.
When I don't use instance the Players health refills when the scene changes, do you maaaaybe know a solution for this?
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Few scene change questions

Post by Tony Li »

Hi,

Add an Invector Stats Saver component to the player GameObject in both scenes, and tick 'Save Across Scene Changes'. Make sure the GameObject names are the same in both scenes or the Invector Stats Savers' Key values are the same. (More info: Saving, Loading, & Scene Changes

Change scenes using any of the techniques listed here. Before leaving the old scene, the Invector Stats Saver will record the player's stats. After entering the new scene, the Invector Stats Saver will apply the recorded stats to the new scene's player.

You can also add an Invector Inventory Saver component if you want to save inventory across scene changes.
eldvbear
Posts: 9
Joined: Mon Aug 10, 2020 4:52 am
Location: Poughkeepsie, NY

Re: Few scene change questions

Post by eldvbear »

Hi there,

Actually, I seem to be having a similar problem. I want to disable the OnDead actions in the vGameController, and just reload the game from the last save point. Currently I am running into the issue when my player dies, two copies respawn at the Spawnpoint location. I have been looking through the documentation but having difficulty understanding how best to accomplish the restart from save in C#. I can generally hold my own if given examples, but a programmer I am definitely not. Any guidance that you could provide would be vastly appreciated.

Thank you,

Ernesto Lopez de Victoria
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Few scene change questions

Post by Tony Li »

Hi,

The respawn is hard coded into Invector's vGameController. You'll need to edit that script. Instead of respawning, reload the last save or open a menu so the player can choose a save to reload.
eldvbear
Posts: 9
Joined: Mon Aug 10, 2020 4:52 am
Location: Poughkeepsie, NY

Re: Few scene change questions

Post by eldvbear »

Hi Tony,

I know I need to modify the spawn functions in the vGameController, but I am just having a little trouble figuring out how to do it properly. I am running into a couple of roadblocks. When my character dies, if the game was not loaded from a save point (such as when a player is starting a new game), when the player character dies, the scene does not reset and a new one is not generated. However, if the game WAS loaded from a previous stored save point, then the character appears at the spot the game was saved. I figure I am probably not doing this correctly in the code.

Any insights you can give would be super helpful.

Thanks,

Ernesto
User avatar
Tony Li
Posts: 21721
Joined: Thu Jul 18, 2013 1:27 pm

Re: Few scene change questions

Post by Tony Li »

Hi Ernesto,

The latest versions of Invector have an onDead event that scripts can hook into. Try adding script like the one below to the player GameObject. It replaces the player's default death event (which respawns) with a method that loads the saved game in slot 0. See the comment for where you can put code if there is no saved game in slot 0.

ReloadWhenDead.cs

Code: Select all

using System.Collections;
using UnityEngine;
using PixelCrushers;
using Invector.vCharacterController;

public class ReloadWhenDead : MonoBehaviour
{
    public int checkpointSaveSlot = 0;

    private IEnumerator Start()
    {
        // Wait for player to initialize:
        var framesToWait = SaveSystem.framesToWaitBeforeApplyData + 1;
        for (int i = 0; i < framesToWait; i++)
        {
            yield return null;
        }
        var controller = GetComponent<vThirdPersonController>();

        // Then unhook Invector's regular death event and replace it with our own:
        controller.onDead.RemoveAllListeners();
        controller.onDead.AddListener(ReloadOnDeath);
    }

    private void ReloadOnDeath(GameObject player)
    {
        if (SaveSystem.HasSavedGameInSlot(checkpointSaveSlot))
        {
            SaveSystem.LoadFromSlot(checkpointSaveSlot);
        }
        else
        {
            // Show load game menu? Go to main menu? etc.
        }
    }
}
eldvbear
Posts: 9
Joined: Mon Aug 10, 2020 4:52 am
Location: Poughkeepsie, NY

Re: Few scene change questions

Post by eldvbear »

Hi Tony,

Thank you for the guidance! I will give it a go at implementing this solution in a clean project. I had a bunch of custom code attached to the existing project’s game controller. If this solution works I’ll rebuild the new one around it. The Save System will streamline things a great deal going forward, by removing the need for alot less graceful self-cobbled-together code.

Thank you so much for your help, and for such a fantastic product!

Ernesto
Post Reply