Mine are hand placed in the scene but also instantiated from inventory when player drops them.
Some are deactivated in the scene when player is not in range (like most other objects to save on overhead)
How would I go about loading and destroying the objects that WERE there but had been picked up?
I added to my objects onawake they would add themselves to a list. And when picked up they would
remove themselves from that list.
(When dropped again they would be added to the list again AND be where I put them, but the original prefabs are still there as well and can't figure out how to remove them)
On my collectible item:
Code: Select all
private void Awake()
{
NotsoSave.prefabInstances.Add(this.gameObject);
}
Code: Select all
public override void Activate(CharacterManager characterManager)
{
if (_inventory != null)
{
if (_inventory.AddItem(this))
{
if (ApplicationManager.instance && _setOnCollect.Count>0)
{
foreach( GameState state in _setOnCollect)
{
ApplicationManager.instance.SetGameState(state.Key, state.Value);
}
}
NotsoSave.prefabInstances.Remove(this.gameObject);
Destroy(gameObject);
}
}
}
EDIT:
I found your SaveDestroyed script, and this is almost working. The issue I have is once I drop the item from the backpack, it destroys because the GUID is on the list when start method runs. It assigns the same GUID to the instantiated prefab.
But then I though what if instead of onstart I just use destroy and add it to a string list, then save that list and on start iterate through the list and destroy the objects..didn't go as planned either...
(Hope it is clear, I have the prefabs saving and loading fine...the issue is on loading a game how to identify the original scene items that were picked up (destroyed) and no longer exist and (re)destroy them so the newly dropped GO are the ones left in scene)