Issue handling child gameobjects on prefabs

Discussion and help for Easy Save 3
Post Reply
syu15
Posts: 16
Joined: Thu May 13, 2021 1:05 am

Issue handling child gameobjects on prefabs

Post by syu15 »

Hello,
I am using the ES3 prefab script on my parent prefab and am experiencing some strange behavior with child gameobjects. It seems like sometimes duplicate child gameobjects get loaded when I restart my game. For example, I have a single child gameobject `TriggerCollider` and sometimes 3 or 4 of these are added to my prefab (this bug is inconsistent as far as I can tell) when I restart my game. Also if I try to destroy a child gameobject (using Destroy) before closing the game/saving the prefab, when I load the game again, a "ghost" gameobject renders which doesn't have the sprite, but still exists. Is there some setup I am missing for these child gameobjects? I have attached a screenshot to demonstrate what I mean.
This is how I am saving/trying to delete the gameobject:

Code: Select all

    void OnApplicationQuit()
    {
        GameObject EmoteObject = GameObject.FindGameObjectWithTag("Emote");
        if (EmoteObject)
        {
        // this does get called, I checked
            Destroy(EmoteObject);
        }

        ES3.Save("bug", gameObject);
    }
Attachments
Screen Shot 2021-06-25 at 6.04.07 PM.png
Screen Shot 2021-06-25 at 6.04.07 PM.png (14.03 KiB) Viewed 1080 times
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: Issue handling child gameobjects on prefabs

Post by Joel »

Hi there,

Destroy() marks an object to be destroyed at the end of the frame, so won't be destroyed immediately. This means that if you destroy it on the same frame as you save it, it will still be saved. For more information see Unity's documentation: https://docs.unity3d.com/ScriptReferenc ... stroy.html

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
syu15
Posts: 16
Joined: Thu May 13, 2021 1:05 am

Re: Issue handling child gameobjects on prefabs

Post by syu15 »

Sure I will take a look at that, thanks. What about the issue of my child gameobjects (TriggerCollider) getting duplicated when I reload my saved parent object? I never instantiate this child object, it is part of the parent prefab so not sure why this is happening.
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: Issue handling child gameobjects on prefabs

Post by Joel »

Hi there,

If my advice didn't resolve your issue, please could you replicate this in a new, empty project with a simple scene and private message it to me with instructions.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply