- Home /
ECS - Translation ignored if prefab's root object is empty object
I'm trying to instantiate a new entity but unfortunately it ignores my given position and spawns itself always at the same location.
Here is the situation:
I've a prefab which one I'm trying to instantiate as entity. It's structure is showed in image below:
In my prefab, the root object Another is an empty object with only one component (`Transform`).
I'm using IConvertGameObjectToEntity
and IDeclareReferencedPrefabs
to convert my prefabs to entities.
Here is my TestAuthoring
class which implements them:
public class TestAuthoring : MonoBehaviour, IConvertGameObjectToEntity, IDeclareReferencedPrefabs
{
public static GameObject _LoadedPrefab;
public static Entity _Entity;
public void Convert(Entity containerEntity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
_Entity = conversionSystem.GetPrimaryEntity(_LoadedPrefab);
}
public void DeclareReferencedPrefabs(List<GameObject> referencedPrefabs)
{
_LoadedPrefab = Resources.Load<GameObject>("Prefabs/Another");
referencedPrefabs.Add(_LoadedPrefab);
}
}
And another piece of code that I use to instantiate new entities:
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
var newEntity = entityManager.Instantiate(TestAuthoring._Entity);
entityManager.SetComponentData(newEntity, new Translation() { Value = spawnPoint });
But unfortunately the spawned entity's position is always (0,0,0).
The strange thing is, when I add a Collider Component to the root object of the prefab, the new spawn performs at the desired position.
I don't know what I'm doing wrong here as I'm new to the ECS of Unity. How can I make this work while keeping my root object without other components?
Your answer
![](https://koobas.hobune.stream/wayback/20220612222601im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Making a smooth camera translation and rotation, C# 1 Answer
Move Objects Relative in Viewport 2 Answers
Language/translation connector to Unity - will it be useful? 0 Answers
Instantiate prefab wihtout dragging prefab into gameObject script 9 Answers
Unable to remove (Clone) suffix (with a possibly a related instantiation issue) 1 Answer