how can i add convertToEntity component to object and get entity to list

I convert gameobject to entity via convertToEntity.

After converted, I wanna add entity to entityList.

how can i do this?

            GameObject instance = Instantiate(prefab);
            Transform transform = instance.transform;
            transform.localPosition = Random.insideUnitSphere * 5f;
            transform.localRotation = Random.rotation;
            transform.localScale = Vector3.one * Random.Range(0.1f, 1f);
            instance.gameObject.AddComponent<ConvertToEntity>();

            //add to List
            //entityList.Add(entity);

No really need to add ConvertToEntity to your game object if you’re doing it this way. You can just call

ConvertToEntity.ConvertHierarchy(instance)

however this won’t solve your issue as it does not return an entity. If you want to get the entity back, you can use

Entity GameObjectConversionUtility.ConvertGameObjectHierarchy(GameObject, World);
2 Likes

thank you this is what i need it