Certain Prefabs not instantiating child objects
Posted: Thu Apr 15, 2021 9:57 am
I have been preparing some of my prefabs by right clicking them and then marking them for easy save. I do this for my town buildings. At the start of the scene the town buildings are then loaded into a list of game objects, this causes the prefabs to be instantiated with all the correct children (mesh renderers, colliders etc). However, after this step i do the same for some farm animals which are also marked as save prefab, they are also loaded into a list of gameobjects, but only their top level object is being loaded in, the children are not.
This issue is a bit confusing to me because when i open the save data to see the townbuildings vs the animals, neither of them store references to their children. I am assuming this is because it doesn't need to save them if it plans to instantiate the prefab at runtime. So this doesn't explain why the chickens dont have their child objects. I can solve this by putting autosave component on them with save children, but this saves a lot of unnecessary data to the save file and still doesn't answer this inconsistency.
for reference, this is the load routine in my TownManager:
and for the animal structure itself, which is responsible for loading the animals:
This issue is a bit confusing to me because when i open the save data to see the townbuildings vs the animals, neither of them store references to their children. I am assuming this is because it doesn't need to save them if it plans to instantiate the prefab at runtime. So this doesn't explain why the chickens dont have their child objects. I can solve this by putting autosave component on them with save children, but this saves a lot of unnecessary data to the save file and still doesn't answer this inconsistency.
for reference, this is the load routine in my TownManager:
Code: Select all
private void LoadEventHandler(EventQueueType eventQueueType, string eventParameter, int quantity)
{
//We only need to load player town builders if the player is actually in their town scene
if (LevelManager.instance.ActiveSceneName != "Overworld_PlayerTown")
return;
if(ES3.KeyExists("PlayerTown_BuildingsGameObjects"))
{
TownBuildingGameobjects = ES3.Load("PlayerTown_BuildingsGameObjects", new List<GameObject>());
}
if (ES3.KeyExists("PlayerTown_Buildings"))
{
TownBuildings = ES3.Load("PlayerTown_Buildings", new List<TownBuilding>());
}
if(ES3.KeyExists("PlayerTown_NonUniqueBuildings"))
{
nonUniqueBuildings = ES3.Load("PlayerTown_NonUniqueBuildings", new Dictionary<string, TownBuilding>());
}
RebuildNPCBuildingReference();
foreach (string guid in nonUniqueBuildings.Keys)
{
nonUniqueBuildings[guid].GetComponent<AnimalStructure>().LoadFromDisk();
}
}
Code: Select all
public void LoadFromDisk()
{
if (ES3.KeyExists(string.Format("{0}_{1}", structureName.Replace(" ", ""), Ref_TownBuilding.Guid)))
{
animalGameobjects = ES3.Load(string.Format("{0}_{1}", structureName.Replace(" ", ""), Ref_TownBuilding.Guid), new List<GameObject>());
animalInventory.LoadInventoryFromDisk();
foodInventory.LoadInventoryFromDisk();
produceInventory.LoadInventoryFromDisk();
}
}