Message System from script on respawn

Announcements, support questions, and discussion for Quest Machine.
GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Message System from script on respawn

Post by GorkaGames »

I'm using "MessageSystem.SendMessage(gameObject, "Kill", QuestKillParameter);" on my script when one enemy is dead and works fine. (I recieve all the messages)
But when my player die out and it respawns apprently the mmesage is not working. I was wondering if it's something related to prefabs or something that must be indicated that has to be persistent between escenes or something.

Thanks.
User avatar
Tony Li
Posts: 22034
Joined: Thu Jul 18, 2013 1:27 pm

Re: Message System from script on respawn

Post by Tony Li »

It should still work. That's one of the advantages of the message system. It's not tied to specific GameObjects.

Are you sure that MessageSystem.SendMessage is being called by your respawned player? You can tick the Quest Machine's Debug Settings > Debug Message System to see what messages are being sent. This will help you verify whether the message is being sent or not.
GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Re: Message System from script on respawn

Post by GorkaGames »

I have revised the message log and actually the message was sent.
Buy then why didn't refresh the counter on the quest?
Maybe is there some parameter that I'm using wrong?

(EDIt: the counter refresh ok all the time as long as the player is not respawned)
User avatar
Tony Li
Posts: 22034
Joined: Thu Jul 18, 2013 1:27 pm

Re: Message System from script on respawn

Post by Tony Li »

This may be related to your other question.

When the player accepts a quest, it adds a copy of the quest to its Quest Journal component. If you destroy the player GameObject to respawn, you will destroy its Quest Journal component, too, which will destroy all of the player's quests. Usually this is what devs want to happen. When you die, you lose your progress.

However, in your case, since the player no longer has those quests, the messages have no receiver.

If you think this is the issue, here are some suggestions to keep the player's quests through respawns:

1. Don't destroy the player GameObject. Instead, keep it and reset it to a starting state. This will keep the Quest Journal component intact.

2. Or, save the Quest Journal component before respawning, and then apply the saved data after respawning. To save the data, call QuestJournal.RecordData() and ApplyData(). For example:

Code: Select all

using PixelCrushers.QuestMachine;
...
string questData = oldPlayer.GetComponent<QuestJournal>().RecordData();
Destroy(oldPlayer);
GameObject newPlayer = Instantiate(playerPrefab);
newPlayer.GetComponent<QuestJournal>().ApplyData(questData);
3. Or put the Quest Journal component on an object that doesn't get destroyed, such as a manager object or a parent of the player. In this case, you'll need to make sure NPCs start dialogue with this object, not the instance of your player prefab.
GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Re: Message System from script on respawn

Post by GorkaGames »

ok, thanks very much for the extense replay.
I'm working on the 3 scenarious to find the right solution. Added to this, how do I restore all the actual elements of the game at that time (when I save the gaem or when I died and spawn the player). I mean with the save script on the quest manager I guess I recover the actual status of the quests, but what do I have to do for recovering the status of the rest elements (Ex: Enemies positions, etc...).

Thanks
User avatar
Tony Li
Posts: 22034
Joined: Thu Jul 18, 2013 1:27 pm

Re: Message System from script on respawn

Post by Tony Li »

Hi,

There are several "Saver" components:
  • Position Saver: Saves a GameObject's position and rotation.
  • Destructible Saver: Records when a GameObject is destroyed or disabled.
  • Active Saver: Records when a GameObject is active or inactive.
  • Enabled Saver: Records when a component on a GameObject is enabled or disabled
General documentation on the save system is in a separate Save_System_Manual.pdf in the Documentation folder.

Most of the Dialogue System's Save System Tutorial also applies to Quest Machine:

GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Re: Message System from script on respawn

Post by GorkaGames »

Point N.2 Ok!
GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Re: Message System from script on respawn

Post by GorkaGames »

Implementing the save system now :)
1. I guess that the Save Sytem Script only have to be 1 time on the scene, what I mean is that if I put on the empty GameObject that says on the PDF Manual, I take it out from the Quest Manager where it was already attached.

2. Now with: PixelCrushers.SaveSystem.SaveToSlot(NSlot); I guess you save the Quests and the Game Objects at the same time, doesn't it?

3. When yo add the Saver Components to a Game Object, do they apply to their childs also? For instance if I have a gameobject where there are 10 enemies under him, do I need to add it to all of them or just the father?

Thanks!
User avatar
Tony Li
Posts: 22034
Joined: Thu Jul 18, 2013 1:27 pm

Re: Message System from script on respawn

Post by Tony Li »

GorkaGames wrote: Mon Sep 24, 2018 4:13 pm1. I guess that the Save Sytem Script only have to be 1 time on the scene, what I mean is that if I put on the empty GameObject that says on the PDF Manual, I take it out from the Quest Manager where it was already attached.
Yes, or keep it on the Quest Machine GameObject. This way they're all together in a single GameObject, which I think is tidier. It's up to you, whichever you prefer.
GorkaGames wrote: Mon Sep 24, 2018 4:13 pm2. Now with: PixelCrushers.SaveSystem.SaveToSlot(NSlot); I guess you save the Quests and the Game Objects at the same time, doesn't it?
Yes. By default, it will save everything to PlayerPrefs. But if you add a Disk Saved Game Data Storer component it will save it to a local disk file instead if you prefer that.
GorkaGames wrote: Mon Sep 24, 2018 4:13 pm3. When yo add the Saver Components to a Game Object, do they apply to their childs also? For instance if I have a gameobject where there are 10 enemies under him, do I need to add it to all of them or just the father?
Since each enemy can move and die independently, add the saver components individually to each enemy. I'll usually add a Position Saver and Destructible Saver to each enemy. If you also want to save the enemy's current health, you can make a copy of the SaverTemplate.cs script to write your own saver component. If enemies die easily (i.e., have few hit points), you don't need to do this; the player won't be able to tell the difference.
GorkaGames
Posts: 178
Joined: Fri Sep 21, 2018 8:38 pm

Re: Message System from script on respawn

Post by GorkaGames »

Is it possible to implement invector's inventory and equipment slots to the save system?
Post Reply