How to get my custom saver to wait a few seconds

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
Aldurroth
Posts: 43
Joined: Wed Jul 20, 2022 8:44 pm

How to get my custom saver to wait a few seconds

Post by Aldurroth »

Hay there, I'm trying to get my pins to remember there connections using the spawnedObjects components "key" identifier that is generated every time an object is spawned into the scene. The issue im having is that if I have an array of items that need to find there connections using the "key" the first one in the list is not remembering it's connection. However if I do everything in reverse (like i did in the second vid) things remember.

If I had to guess it's that each pinSaver script is running in the order it's found in the hierarchy. Which means while the first object dose remember which spawned object key to look for, that object which is further down the list has not loaded it's key yet, so the first object can't find what it's looking for. If this is the case do you think I could save a list of objects that can have components assigned to it when I save? I think there called structs but its 12:30am now and I cant remember. Perhaps this way I can use this external pin saver to link everything up after it loads everything first. So load components, then connect.

Any idea why and how to save and load all my things and everyone find everyone else? I'll provide the saver so you have an idea what I'm trying to do.

Sorry for the lack of audio I thought my mic was recording...apparently not. But I think you can see the problem.

Script:

using System;
using System.Collections;
using PixelCrushers;
using UnityEngine;
using UnityEngine.UI;


public class PinSaver : Saver
{
[SerializeField] GameObject corkBoard;
public string point_1name;
[SerializeField] DrawLine drawLine;
[Serializable]
public class Data
{
public string point_1name;
public string myKey;
}
/*
private void Start()
{
if (corkBoard == null)
corkBoard = GameObject.FindGameObjectWithTag("CorkBoard");
}*/

public override string RecordData()
{
var data = new Data();

// Save name of texture
data.point_1name = point_1name;

// Save my own key
data.myKey = this.GetComponentInParent<SpawnedObject>().key;

drawLine.myKey = data.myKey;

/*if (data.point_1name != null)
print(data.point_1name);*/

return SaveSystem.Serialize(data);
}

public override void ApplyData(string s)
{
if (string.IsNullOrEmpty(s)) return; // If we didn't receive any save data, exit immediately.
var data = SaveSystem.Deserialize<Data>(s);

if (data == null) return; // Serialized string isn't valid.

// Assign point 1 name
point_1name = data.point_1name;
drawLine.point_1PinName = data.point_1name;

// Assign myKey
drawLine.myKey = data.myKey;

if (data.point_1name != String.Empty)
{
// (1)My array to loop threw...the parent of every object on board
GameObject[] corkBoard;
// (2)
corkBoard = GameObject.FindGameObjectsWithTag("Pin");
// (3)
for (int i = 0; i < corkBoard.Length; i++)
{
//print(corkBoard.name + " " + i);
print("My key is " + corkBoard.transform.GetComponent<DrawLine>().myKey);
if (corkBoard.transform.GetComponent<DrawLine>().myKey == point_1name)
{
//print(data.point_1name);
//print(corkBoard.transform.GetComponent<SpawnedObject>().key);

drawLine.point_1 = corkBoard.transform;
print("I found my object");
return;
}
else
{
print("Nothing. If there is a connection something is still wrong. My key is " + corkBoard.transform.GetComponent<DrawLine>().myKey);
}
}
}
}
}

Video 1:
Video 2:
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to get my custom saver to wait a few seconds

Post by Tony Li »

Hi,

Did you set your Save System component's Frames To Wait Before Apply Data to 1? For spawned objects, it needs to be 1 or higher.
Aldurroth
Posts: 43
Joined: Wed Jul 20, 2022 8:44 pm

Re: How to get my custom saver to wait a few seconds

Post by Aldurroth »

No, how would I do this and where would I put this function?
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to get my custom saver to wait a few seconds

Post by Tony Li »

Hi,

Locate your Save System component. It's probably on your Dialogue Manager GameObject or a separate Save System GameObject. You can enter "t:SaveSystem" in the Hierarchy window's search bar to help find it. Then set its Frames To Wait Before Apply Data field to 1.

If you're looking at the post-it note example scene I shared last week, please look over the --README.txt-- GameObject that's in the scene. It might have some other useful tips.
Aldurroth
Posts: 43
Joined: Wed Jul 20, 2022 8:44 pm

Re: How to get my custom saver to wait a few seconds

Post by Aldurroth »

That worked. Thank you very much.
Aldurroth
Posts: 43
Joined: Wed Jul 20, 2022 8:44 pm

Re: How to get my custom saver to wait a few seconds

Post by Aldurroth »

Alright probably last question for the week (hopefully), I need a start screen that can hold multiple saved game starts. So what I meen is I start a new game, I get so far, decide I want to start over. I save my current game progress and it is stored on the home page. I start another game and this new game is also saved on the home page. From time to time I perhaps want to switch between the two saved game for some reason.

How dose one set this up in Pixle Crushers?
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to get my custom saver to wait a few seconds

Post by Tony Li »

Hi,

You could either hook up a bunch of UI Buttons to Save System Methods components and configure their OnClick() events to call SaveSystemMethods.LoadOrRestart(slot), or use/steal ideas from the free Menu Framework addon available on the Dialogue System Extras page.
Aldurroth
Posts: 43
Joined: Wed Jul 20, 2022 8:44 pm

Re: How to get my custom saver to wait a few seconds

Post by Aldurroth »

Alright I can look into this slot thing. Is this data saved in a component or would I need to write my own? Either way is fine.
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to get my custom saver to wait a few seconds

Post by Tony Li »

The save system is slot-based. Once you've set it up, you can save games in any number of slots, and it will save using whatever ***SavedGameDataStorer component you've added to the GameObject with the Save System component. If you've added a DiskSavedGameDataStorer, it will save games to local disk files. If you've added a PlayerPrefsSavedGameDataStorer instead, it will save games to PlayerPrefs. You can also write your own storers by making your own subclass of SavedGameDataStorer.
Post Reply