Destructible Saver question

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
rykaan
Posts: 75
Joined: Tue Feb 11, 2020 6:22 am

Destructible Saver question

Post by rykaan »

Hi Tony,

Would it be possible to access and change the 'destroyed' bool in a destructible saver directly instead of actually destroying it? Or would that cause problems? When a monster is killed in my game the animation plays, falls over etc but then there may be some interaction between other monsters or characters that couldn't be done if the gameObject is destroyed immediately (spotting the corpse and investigating the area for example). I don't want the monster to respawn next time the level is loaded, but if the player saves/changes scene the monster will come back to life since the destructible saver hasn't triggered.

Is there a decent way to affect the destructible saver like this? Or would a custom saver make more sense? I am destroying the monster immediately under different circumstances, so using the same saver for this system would be super useful.

Cheers,
Rob
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Destructible Saver question

Post by Tony Li »

Hi Rob,

Create a short subclass of DestructibleSaver that exposes the RecordDestruction() method. Example:

MyDestructibleSaver.cs

Code: Select all

using UnityEngine;
using PixelCrushers;
public class MyDestructibleSaver : DestructibleSaver
{
    public void Killed()
    {
        RecordDestruction();
    }
}
Use this instead of DestructibleSaver. When the enemy is killed, called the Killed() method.
User avatar
rykaan
Posts: 75
Joined: Tue Feb 11, 2020 6:22 am

Re: Destructible Saver question

Post by rykaan »

Excellent!

Works like a charm. I was starting to write code to force the game to destroy dying monsters before saving/scene changes ¬_¬. Figured this would be a FAR better solution if possible.

Cheers,
Rob
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Destructible Saver question

Post by Tony Li »

Great! Not that it helps you right this minute, but I'll make RecordDestruction() public in the next update so in the future people will be able to call it directly instead of having to use a subclass to access the method.
Post Reply