Character save at save point

Announcements, support questions, and discussion for the Dialogue System.
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: Character save at save point

Post by Tony Li »

Let's focus on getting one Persistent Active Data working. Then the same solution will probably apply to the others.

Please post a screenshot of the inspector view for this Persistent Active Data component. Expand any parts of the Condition section that you're using (e.g., Lua conditions, Accepted Tags, etc.).

Then play the game in the Unity editor and load a saved game. In the Console window, click on the line that reports the loaded saved game info. It'll say something like "Loading saved game. Save game data: .....". Press Ctrl+C to copy it to the clipboard, then paste it into an email to tony (at) pixelcrushers.com or PM it to me.
User avatar
supadupa64
Posts: 200
Joined: Sun Mar 06, 2016 9:40 pm
Contact:

Re: Character save at save point

Post by supadupa64 »

I have my variables set up like this:
variable.jpg
variable.jpg (55.07 KiB) Viewed 2991 times
I deleted the " " in the lua command area and still loads a bunch of stuff that shouldn't show. So now as an example it looks like this:
Variable[Trigger___Activate_plant_group_one_area] ~= true

I also noticed that when I removed the quotes some of the triggers didn't setactive the object. There was an error with the variable. So I put the quotations back and it worked again... It still loaded everything on load.
User avatar
supadupa64
Posts: 200
Joined: Sun Mar 06, 2016 9:40 pm
Contact:

Re: Character save at save point

Post by supadupa64 »

I put the persistence active date component on a separate collider and it didn't work. Anyway, so far the only thing that saves and loads perfectly are the quests the player is on. Let me give an example of a situation with that I just saw.

Let's say I have to collect 10 scrolls. I accept the quest and walk up to the first scroll. If I collect that scroll I now have 1/10 collect. The scroll is destroy on use, so it goes away. I save the game and load it, here's what happens: I am still on the quest and still have 1/10 collected which is great. The probably is that on load the scroll I just collected now is there again. The player could potentially just collect the second one, save/load and keep doing that until 10/10 are collected. Is there something in the code that needs to be fixed possibly? This is the same situation with my areas saving and loading. All the areas active on load which also happens with the scrolls. Although, not all the quest items throughout the game load, so that works. It's just if I'm on the quest this happens. I assume these things are probably connected with the persistent active data component?
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: Character save at save point

Post by Tony Li »

Here's an example:

ScrollQuestExample_2016-10-31.unitypackage

In this example, there are three interactable objects:
  • QuestStartTrigger: When the player enters this trigger, it starts the quest to pick up 2 scrolls. (A blue platform)
  • Scroll01: A scroll that can be picked up. (A red box)
  • Scroll02: Another scroll that can be picked up. (Another red box)
Scroll01 and Scroll02 are grouped under an inactive GameObject named QuestScrolls.

The dialogue database has these variables:
  • numScrollsCollected (Number) = 0
  • Scroll01Collected (Boolean) = False
  • Scroll02Collected (Boolean) = False
The components on the GameObjects are:
  • QuestStartTrigger:
    • Dialogue System Trigger: Sets the quest active; Runs the sequence "SetActive(QuestScrolls,true); SetActive(QuestStartTrigger,false)"
  • Scroll01:
    • Destroy On Trigger Enter (simple script that destroys the GameObject when the player touches it)
    • Persistent Destructible: Sets Scroll01Collected to true when destroyed.
    • Increment On Destroy: Increments numScrollsCollected.
  • Scroll02: set up similarly to Scroll01.
There's another empty GameObject (no collider, no rigidbody, nothing except a Transform) named PersistentActiveData containing these components:
  • Persistent Active Data: Target=QuestStartTrigger, Condition=Only if quest is unassigned.
  • Persistent Active Data: Target=QuestScrolls, Condition=Only if quest is active.
  • Persistent Active Data: Target=Scroll01, Condition=Variable["Scroll01Collected"] ~= true
  • Persistent Active Data: Target=Scroll02, Condition=Variable["Scroll02Collected"] ~= true
This might be the issue in your scene: Notice in my example that Scroll01 has a Persistent Destructible and the PersistentActiveData GameObject has a Persistent Active Data component for Scroll01. This is because Scroll01 starts the scene inactive. In this example, the Persistent Destructible's purpose is to set Scroll01Collected when Scroll01 is destroyed. However, Persistent Destructible won't re-destroy it on load because Scroll01 (and its Persistent Destructible component) is inactive when the scene is loaded. To make sure it gets destroyed properly on load, I also added a Persistent Active Data component that's guaranteed to be active on load.
User avatar
supadupa64
Posts: 200
Joined: Sun Mar 06, 2016 9:40 pm
Contact:

Re: Character save at save point

Post by supadupa64 »

Awesome, so I started testing this on a quest and it looks like it works perfect! I think the biggest difference is that I placed all persistent active data items into one empty object. The demo scene really helped A LOT! THANKS!!!

Anyway, I assume this will also work if I do this for my SetActive items in the scene?

Also, I was going to place every persistent active data component for everything in my game inside one empty game object, but I guess that wouldn't work since there is a quest condition. Is that correct? I assume that's it, but I think I'll ask you before I go and make hundreds of changes to make sure.
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: Character save at save point

Post by Tony Li »

Each Persistent Active Data component has its own condition. So long as your SetActive items set something that can be tested in a condition, it should work. Test with one or two SetActive items first to double-check your process.
User avatar
supadupa64
Posts: 200
Joined: Sun Mar 06, 2016 9:40 pm
Contact:

Re: Character save at save point

Post by supadupa64 »

I feel like I'm missing a key step, but I can't quite place my finger on it for saving my SetActive objects.

1) Here's my first object with persistent active data component. Here's what I have:
a) Target
b) Lua Condition: Variable
c) I also created a variable
i) PLANTS ALL HERE and cliffs text
ii) False boolean
d) Quest condition (I made this quest (RuctionGames) and set it to active during the whole game with the idea since it's always active everything I use it with will always be saving. I assume that works.
i) RuctionGames active
1.jpg
1.jpg (81.63 KiB) Viewed 2971 times
2) This is my trigger that activates the "PLANTS ALL HERE and cliffs" area when I run through it.
a) It's probably easier if you just look at it.
i) I think something it wrong with this here because if I delete the variable in the lua condition the trigger works, but if I leave it, the trigger only works once in game as far as I can tell and is basically broken.
2.jpg
2.jpg (125.89 KiB) Viewed 2971 times
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: Character save at save point

Post by Tony Li »

This is my understanding of your goal, in plain English:
  • There is an inactive GameObject named "PLANTS ALL HERE and cliffs".
  • When the player enters a certain trigger collider, activate "PLANTS ALL HERE and cliffs".
  • In saved games, remember whether "PLANTS ALL HERE and cliffs" is active or inactive.
Here's how I'd implement that:
  • In your dialogue database, define a Boolean variable named "Trigger setactive scene 2 start area cave". Leave its Initial Value false.
  • On your trigger collider, add a Sequence Trigger with:
    • Sequence:

      Code: Select all

      SetActive(PLANTS ALL HERE and cliffs); SetVariable(Trigger setactive scene 2 start area cave, true)
    • Condition > Lua Conditions:

      Code: Select all

      Variable["Trigger_setactive_scene2_start_area_cave"] ~= true
    • On your PersistentActiveDataAll GameObject, add a Persistent Active Data component with:
      • Target: PLANTS ALL HERE and cliffs
      • Condition > Lua Conditions:

        Code: Select all

        Variable["Trigger_setactive_scene2_start_area_cave"] == true
You don't need a RuctionGames quest.
User avatar
supadupa64
Posts: 200
Joined: Sun Mar 06, 2016 9:40 pm
Contact:

Re: Character save at save point

Post by supadupa64 »

So far it doesn't work yet.
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Re: Character save at save point

Post by Tony Li »

Hi Scott,

How can I help? Would it help to provide a new example scene that you could base your configuration on?
Post Reply