Read through the conversion workflow documentation but can’t figure out the proper use of IDeclareReferencedPrefabs
I would like to have a list of prefabs I can access from any system to spawn those prefabs.
In NetCode I use the GhostPrefabCollectionComponent to access prefabs and instantiate them in systems.
I created a “PrefabCollection” GameObject in my SubScene and added the following script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.Entities;
public class PrefabReference : MonoBehaviour, IDeclareReferencedPrefabs
{
public GameObject Prefab1;
public GameObject Prefab2;
public void DeclareReferencedPrefabs(List<GameObject> referencedPrefabs)
{
referencedPrefabs.Add(Prefab1);
referencedPrefabs.Add(Prefab2);
}
}
I cannot for the life of me figure out how to reference this “List” of GameObjects in other systems to create prefabs.
I want to build something like:
public class AsteroidSpawnSystem : SystemBase
{
private Entity m_Prefab;
protected override void OnCreate()
{
m_Prefab = DeclareReferencedPrefabs.Prefab1
}
protected override void OnUpdate()
{
EntityManager.Instantiate(m_Prefab);
}
}
How do I access the prefabs I have added to the list?