Page 1 of 1

Destructible Saver question

Posted: Wed Apr 29, 2020 7:33 am
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

Re: Destructible Saver question

Posted: Wed Apr 29, 2020 8:16 am
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.

Re: Destructible Saver question

Posted: Thu Apr 30, 2020 5:31 am
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

Re: Destructible Saver question

Posted: Thu Apr 30, 2020 9:33 am
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.