0
\$\begingroup\$

Finally, DOTS is completely released with Unity's 2022 version, so I decided to learn it using the latest tutorial by code monkey. He is using URP for this project.

My question is, URP or HDRP necessary to run Unity ECS? Or especially the SubScene?

I ask because, after following the 15-minute tutorial, I am not able to render my simple cube object in the game view under the sub-scene. Note: I am not using EntityGraphics Pacakge.

When I searched for this, I found an issue on the issue tracker that says that SubScenes will work with URP.

Is there any way to use Unity SubScenes with a built-in render pipeline? Or are SubScenes only compatible to use with URP/HDRP?

\$\endgroup\$
3
  • 2
    \$\begingroup\$ The issue you linked says pretty explicitly "Entities are using Entities Graphics (EG) package to render. If no EG package is present, nothing is rendered. EG package does not support Built-In rendering pipeline." \$\endgroup\$
    – DMGregory
    Feb 23 at 12:22
  • \$\begingroup\$ URP/HDRP are not required to run ECS if you just want to use entities for batch processing. URP/HDRP ARE required to RENDER entities. \$\endgroup\$
    – DMGregory
    Feb 26 at 13:40
  • \$\begingroup\$ I think I got the answer in your comment. So if we want to render the entities then we require URP/HDRP. But we can use ECS for batch processing. What kind of batch processing? can you explain this in the answer section. I just want to know the big picture, that what when to use or what are the compatiblities issues among different system. I am not able to imagine that what is the use of ECS without rendering. \$\endgroup\$ Feb 27 at 4:20

3 Answers 3

0
\$\begingroup\$

At 4:10 of the tutorial you linked, Code Monkey says:

The other [package] that we need in order to be able to render things is the Entities Graphics. You only need this one if you actually want to render entities, meaning you can just use entities without any entities visual.

...

Now one more note related to this Entities Graphics: this one only works either URP or HDRP. It does not work with the built-in render pipeline.

The description for this package says it provides the "systems and components for drawing meshes using DOTS".

So you can use DOTS entities without this package / without URP or HDRP, you just won't be able to directly draw meshes with those entities.

What good is an entity you can't draw? Consider off-screen simulation. Imagine you're making a city management sim. You want to be able to update the simulation of the whole city all the time, even if not every agent/process in the city is a mesh currently visible on-screen. And you want to do that as efficiently as possible, without impacting framerate. So farming out that simulation to DOTS entities that can distribute work among background threads and benefit from burst compiling makes a lot of sense.

Then, if a subset of those entities correspond to pedestrians / vehicles / buildings / props / animals visible in the current camera frame and zoom level, you can spawn conventional game objects, particle systems, or VFX to render just that subset, without rendering a whole sub-scene of entities directly.

We used a technique similar to this in the game Starlink: Battle for Atlas (not in Unity) to handle updating the behaviour of allied and enemy factions on the other side of the planet or on other planets from where the player was currently playing. When the player came in-range of one of these background "SimUnits", we up-rezzed it to a fully-realized game object with a display mesh and full AI behaviour, then when they went out of range, de-rezzed it back to a SimUnit in the pool for efficient batch simulation.

If your application requires rendering many entities, then you'll need to switch to URP/HDRP and install the Entities Graphics package to enable this.

\$\endgroup\$
1
\$\begingroup\$

I have successfully used entities with the regular render pipeline in one project. I did this by creating a MonoBehavior I called "EntitySurrogate". Its Update-method queries the entity manager to retrieve the components with the position and rotation of the entity (In my case, a custom component called MovementComponent) and use their values to set the position and rotation of its own transform component. This allows to create traditional game objects which mimic the movement of specific Entities in the ECS world.

using UnityEngine;
using Unity.Entities;        

public class EntitySurrogate : MonoBehaviour {

    public Entity entity;
    private EntityManager manager;

    void Start() {
        manager = World.DefaultGameObjectInjectionWorld.EntityManager;
    }

    void Update() {
        var movement = manager.GetComponentData<MovementComponent>(entity);
        transform.SetPositionAndRotation(
            new Vector3(movement.pos.x, 0.0f, movement.pos.y),
            Quaternion.Euler(0f, movement.rotation, 0f)
        );
    }
}

However, if you do this for all the entities in your game, you will probably not benefit a lot from the ECS performance gains. I only did this because in my specific use-case there was a background simulation involving tens of thousands of entities, but less than a hundred of them visible at any time. So the overhead of doing this wasn't so bad, because I only needed these "Entity Surrogates" for a very small subset of all entities. But in most situations it would probably be better to bite the bullet and use either HDRP or URP where you can use the Entity Graphics package.

\$\endgroup\$
0
\$\begingroup\$

URP or HDRP isn't necessary to run Unity ECS. However, to render an entity, you require the Entity Graphics package, which doesn't function on the Built-in Render Pipeline.

In fact, an entity isn't solely about the visual aspect of your game; it can encompass various elements. If you intend to render an entity, URP is a necessity. Otherwise, if you wish to utilize other aspects of an entity, you can employ it within the Built-in Render Pipeline.

For better Details Check @DMGregory answer and also check @Philipp answer which is helpful to understand the context of entity.

\$\endgroup\$
0

You must log in to answer this question.

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