Page 6 of 10
Re: Character save at save point
Posted: Thu Jul 07, 2016 4:23 pm
by supadupa64
Hey so here's another thing. My load works every time except for the first time as usual. But here's another issue.
When I go through a trigger to do something it doesn't save
. What would I add to the trigger to the game remembers when the sequence is? I have a sequence trigger on a trigger collider.
Re: Character save at save point
Posted: Thu Jul 07, 2016 8:12 pm
by Tony Li
Hi,
supadupa64 wrote:Hey so here's another thing. My load works every time except for the first time as usual. But here's another issue.
When I go through a trigger to do something it doesn't save
. What would I add to the trigger to the game remembers when the sequence is? I have a sequence trigger on a trigger collider.
Use a Lua variable to remember it.
I'll use a concrete example to explain the process. Let's say you have a sequence that drops a bunch of rocks from the ceiling when the player first enters a cave. You want your saved game to remember that the player has previously entered the cave so it doesn't incorrectly drop those rocks again.
Here are the steps:
1. Define a Lua variable named "EnteredCave". Set its Type to Boolean and its value to False. This variable will always be recorded in your saved games.
2. Set up a trigger collider GameObject in the mouth of the cave, and add a Sequence Trigger.
3. Open the Sequence Trigger's Condition section, and add this Lua condition:
This means the Sequence Trigger will only fire if EnteredCave hasn't been set true yet.
4. In the Sequence field, add your sequencer commands to make the rocks fall. Also add a
SetVariable() sequencer command to set EnteredCave true. For example:
Code: Select all
SetActive(Rocks);
Audio(Rumble);
SetVariable(EnteredCave, true)
That should handle the sequence/saved game issue. But it still bugs me (and I'm sure you, too) that the game doesn't load properly the first time. If you ever want me to dig into this, please send me a reproduction project. I'll PM you access info for the FTP site, which can handle files up to 4 GB. If your project is bigger than that, you'll need to find another way to get it to me, such as Dropbox.
Re: Character save at save point
Posted: Thu Jul 07, 2016 9:07 pm
by supadupa64
Got it thanks!
Here's the thing. I have about 60 or so triggers in the game. A lot of them just enable or disable objects with SetActive(). Are you saying that if I want the game to save the SetActive() command I have to set up a variable for every sequence trigger?
Re: Character save at save point
Posted: Thu Jul 07, 2016 9:22 pm
by supadupa64
Let's say my player goes through a trigger collider and it enables lots of trees. If I go through that trigger, save the game, then load it, those lots of trees are not there because the trigger didn't save. Maybe you got that the first time though.
Re: Character save at save point
Posted: Thu Jul 07, 2016 10:12 pm
by Tony Li
supadupa64 wrote:Here's the thing. I have about 60 or so triggers in the game. A lot of them just enable or disable objects with SetActive(). Are you saying that if I want the game to save the SetActive() command I have to set up a variable for every sequence trigger?
You don't really have to set up the variables ahead of time.
If a variable isn't defined, it isn't true. [Corrected: It doesn't treat it as false, but as nil, which is not true.] So if "EnteredCave" isn't defined, the Condition 'Variable["EnteredCave"] ~= true' on the Sequence Trigger will still be true, so it will still run the sequence.
Likewise, if you put SetVariable(EnteredCave,true) in the sequence, it will automatically set up the variable for you if it's not already set up.
supadupa64 wrote:Let's say my player goes through a trigger collider and it enables lots of trees. If I go through that trigger, save the game, then load it, those lots of trees are not there because the trigger didn't save. Maybe you got that the first time though.
Use a
Persistent Active Data component. For the tree example, let's say your Sequence Trigger looks like this:
- Condition > Lua Condition: (not "==false")
- Sequence:
Code: Select all
SetActive(TreesParent); SetVariable(EnabledTrees,true)
(For simplicity, I'm assuming your trees are grouped under an empty GameObject named "TreesParent".)
Add a Persistent Active Data component to any GameObject that starts active in the scene. Configure it like this:
- Target: TreesParent
- Condition > Lua Condition:
When a game is loaded, the Persistent Active Data component will check the value of the "EnabledTrees" variable. If the variable is true, it will set TreesParent active. Otherwise it will set TreesParent inactive.
Re: Character save at save point
Posted: Thu Jul 07, 2016 10:55 pm
by supadupa64
Ok, so I add the Persistent Active Data component to any parent object that is activated through a trigger?
1) Trigger collider
sequence trigger - SetActive(tons of trees)
2) tons of trees (this is the name of the parentobject)
add Persistent Active Data component
yes?
Re: Character save at save point
Posted: Fri Jul 08, 2016 6:48 am
by Tony Li
Close, but here are a few clarifications:
The Sequence Trigger needs to run SetActive(tons of trees) and SetVariable(ActivatedTrees), and it must have a Lua condition that Variable["ActivatedTrees"] isn't true (that is, it hasn't already activated the trees). [Corrected: This post previously said that the variable should be false. It should really be not-true.]
The Persistent Active Data component must be on a GameObject that starts active in the scene. So it can't be on tons of trees. You could create another GameObject, maybe called Persistent Active Components, and add all of your Persistent Active Data components to it.
Re: Character save at save point
Posted: Fri Jul 08, 2016 5:36 pm
by supadupa64
Ok, here's what I have so we can use this specific example below. It all works, I'm just trying to get it to save it's current state, active or inactive.
- maptrigger.jpg (128.81 KiB) Viewed 3328 times
I would place the "persistent active data" component on the "empty gameobject" which I named "scrollstartmap?" I'm not sure if that's it because I tried that and it didn't work.
Here's what the empty game object looks like.
- scrollmap.jpg (109.37 KiB) Viewed 3328 times
Re: Character save at save point
Posted: Fri Jul 08, 2016 8:32 pm
by Tony Li
It's almost there! Persistent Active Data needs to be on a GameObject that's already active whenever the scene starts. Here's an example:
1. In your Sequence trigger, (1) set Condition to require that a variable ("MapTrigger" in this example) is NOT true using the "~= true" syntax [corrected from "==false"], and (2) in the Sequence, set the variable true:
2. On an
active GameObject (not startscrollmap), add Persistent Active Data. Configure it to set startscrollmap active or inactive based on the value of the MapTrigger variable. In the screenshot below, I created a separate, active GameObject named "persistent active data":
I put it on a separate GameObject just to make the screenshot shorter. There's no reason why you couldn't put the Persistent Active Data component on the same GameObject as the Sequence Trigger (i.e., the maptrigger GameObject):
Re: Character save at save point
Posted: Fri Jul 08, 2016 9:21 pm
by supadupa64
Do I need to reference a database?
Do I have to create a variable in the database or can I just type it into the lua without creating a variable in the database?