Prefabs duplicating themselves at each run

Discussion and help for Easy Save 3
Post Reply
eovento
Posts: 10
Joined: Fri Jan 03, 2020 1:31 pm

Prefabs duplicating themselves at each run

Post by eovento »

Good Morning! :)

My application is very simple, consisting of a single prefab with a single script on it. And what I would need is to individually save the values on each of the instances of this prefab.

It was working perfectly before I made it a prefab. While it was only a gameobject with a script on it.
I was using the AutoSave script, have checked all the variables I need under the Type section in ES3 settings, and all was great.

But now that I made it a prefab, with the prefab script on it, every single time I run the application it will automatically add one more instance of the prefab on the scene. For no reason at all. And I really can't have this happening as the instances should be instantiated at very specific moments.

What is happening is that if an instance is already in the Hierarchy before runtime, it will add another one. And if I stop, do nothing, then hit Play again, it will add a third one. And so on.
And the same happens if there are no instances in Hierarchy - it will add another one, and this is what I need to prevent.
I tried looking for it on the documentation before reaching for you, but could not find anything regarding this behavior.

Thank you Joel, and wish you a super weekend! :)
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Prefabs duplicating themselves at each run

Post by Joel »

Hi there,

ES3Prefab is for prefabs instantiated at runtime. If your object exists in the scene prior to runtime then it's a prefab instance rather than a prefab, so you shouldn't use the ES3Prefab Component.

Hope this helps :)

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
eovento
Posts: 10
Joined: Fri Jan 03, 2020 1:31 pm

Re: Prefabs duplicating themselves at each run

Post by eovento »

Thank you for quick reply!

Understood about the prefab script, attached only to the prefab itself. (I was adding it to the object before making a prefab out of it).
But, apart from prefab script, there is still some weird thing going on, on the auto save alone.
It's easy to reproduce.

If you create a new empty object in the hierarchy, and add nothing but the ES3 Auto Save script to it, then run... nothing weird will happen yet.
Stop.
Simply run a second time. - This time a duplicate of the object will be generated (don't know why). And any time you run it again, there will be a duplicate together with the original in the hierarchy.

This is particular problematic in my project as it's not a game, and each of my scripts make repetitive API calls to a specific server. When I have duplicates, I multiply these calls, which might cause some harm over a short period of time.

I would need no instances to be ever generated automatically.
I have basically one prefab that gets instantiated on specific moments during runtime, holding one component only. So I will need ES to keep this instances safe. (On this prefab I have ES3 autosave and prefab components)
And on Hierarchy I have one Object which will be the parent of all instances of that prefab. On this one I also attached the Auto Save (not prefab), and checked it to save children.
This is basically my whole project. :)

I'm sorry for all details, it was just a way to make it easy to visualize; not that I expect a personal help on my project. :))
The important here is the duplicating issue.
(I also often clear the persistent data path and player prefs, so it's not the issue)

Thank you again,
Daniel
User avatar
Joel
Moodkie Staff
Posts: 4846
Joined: Wed Nov 07, 2012 10:32 pm

Re: Prefabs duplicating themselves at each run

Post by Joel »

Hi Daniel,

Thanks for the detailed information, I've managed to replicate this at my end. It seems like there's a state where the reference manager fails to get updated with new references (meaning Easy Save isn't aware that your GameObject already exists).

This is an easy fix at our end and I'll submit an update to Unity for approval today. In the meantime if you private message me your invoice number I'll be happy to send the update over.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
eovento
Posts: 10
Joined: Fri Jan 03, 2020 1:31 pm

Re: Prefabs duplicating themselves at each run

Post by eovento »

Thank you, Joel!
I'll send you the invoice.
Post Reply