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

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Of course! I knew this, I can't believe I forgot the Hybrid Renderer, Thank you!! \$\endgroup\$ – MetaMax Nov 1 '19 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..

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.