#Can I convert a GameObject into an Entity of a baker class?

1 messages · Page 1 of 1 (latest)

olive palm
#

I have this Scriptable Object which contains a reference to a Prefab i want to send to my player inventory as an Entity so it can spawn it later.
Since the has object is sent to the inventory when the user clicks a button, this happens inside of a MonoBehaviour that handles what to do when the buttons are clicked.
Is there a way to convert this Prefab to and Entity inside this MonoBehaviour?

The code as it is:

//Inventory
public struct Inventory : IComponentData {
    public NativeList<Entity> Towers;
}

//Upgrade Data
public class TowerData : ScriptableObject {
    //[...]
    [SerializeField] private GameObject towerPrefab;
}

//The monobehaviour
//[...]
inventorySingleton.Towers.Add(_upgradesToChooseFrom[upgradeIndex].TowerPrefab); // this needs to be an Entity
//[...]

Thanks in advance!

sterile junco
#

Conversion is editor only and must be done at compile time in subscenes

#

if your game is ecs you also shouldn't do any ecs logic via monob

#

Instead add listener via system