2
\$\begingroup\$

I have not worked with ECS before, so I was following the tutorial by Unity's Mike Geig on Youtube to convert gameObjects to ECS from Unite Copenhagen, and this code does nothing, and there are no errors:

using Unity.Entities;
using Unity.Transforms;
using UnityEngine;

public class SpawnAsteroidECS : MonoBehaviour
{
    public GameObject AsteroidPrefab;

    EntityManager manager;
    Entity AsteroidEntityPrefab;

    void Start()
    {
        manager = World.Active.EntityManager;
        AsteroidEntityPrefab = GameObjectConversionUtility.ConvertGameObjectHierarchy(AsteroidPrefab, World.Active);
    }

    void Update()
    {
        if (Input.GetKey(KeyCode.Mouse0))
        {
            for (int i = 0; i < 100; i++)
                SpawnTheAsteroids();
        }
    }

    private void SpawnTheAsteroids()
    {
        Entity asteroid = manager.Instantiate(AsteroidEntityPrefab);

        manager.SetComponentData(asteroid, new Translation { Value = transform.position });
        manager.SetComponentData(asteroid, new Rotation { Value = Quaternion.identity });
        print("Done");
    }
}

What am I not doing?

EDIT: The entity debugger does show that there are entities, but i dont actually see it in the game.

\$\endgroup\$
10
  • \$\begingroup\$ Did you attach that MonoBehaviour to an active game object in your scene? \$\endgroup\$
    – Philipp
    Commented Nov 1, 2019 at 9:36
  • \$\begingroup\$ Yes I did attach it on an active object. \$\endgroup\$ Commented Nov 1, 2019 at 9:42
  • \$\begingroup\$ It does create entities, but I can't see it in the game. \$\endgroup\$ Commented Nov 1, 2019 at 9:47
  • \$\begingroup\$ Does the asteroid prefab show up when you put it into the scene as a regular game object? \$\endgroup\$
    – Philipp
    Commented Nov 1, 2019 at 10:06
  • \$\begingroup\$ Yes, I can instantiate it with a normal monobehavior gameobject. I just want to do the same with ECS. \$\endgroup\$ Commented Nov 1, 2019 at 10:07

2 Answers 2

3
\$\begingroup\$

Its look like that you have not installed the "Hybrid Renderer" Package.

When you want to convert Game objects to Entities then you have to also install "Hybrid Renderer" from package manager.

  1. Open up package manager from Windows -> Package manager.
  2. Enable "Show Preview Packages" from Advance tab. enter image description here

  3. Then search "hy" then Install "Hybrid Renderer".

    enter image description here

Same thing happen to me and from some where on internet i found this and it resolved my issue immediately.I am sorry i don't have link to it but it workes.

I hope this will help.

\$\endgroup\$
1
  • \$\begingroup\$ Of course! I knew this, I can't believe I forgot the Hybrid Renderer, Thank you!! \$\endgroup\$ Commented Nov 1, 2019 at 13:23
0
\$\begingroup\$

I was stuck with this problem for a long time, it seems that for Unity 2020.1.2f1 that I am running, "Hybrid Renderer" did not show up in the Package Manager. Looking at the docs made me think it was now a part of "Universal RP" but installing that did not make a difference. It was first when I manually added "com.unity.rendering.hybrid": "0.8.0-preview.19", to the manifest file that the entities started to render.

Btw, Entites did not show up either in PM, but by installing "Havok Physics for Unity" then it was downloaded as an dependency..

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .