Hey. I’m trying to convert a very small project into ECS; I want to render some meshes from a System. I’d like to draw things without baking any gameObjects. I have the meshes; they work without ECS. What I can’t figure out is how to pass those meshes to something to be drawn.
Should I be looking at RenderMeshUtility.AddComponents? I think I saw someone suggesting just using BatchRendererGroup, and I found a tutorial that just gave one entity a rendermesh. The thing is, I don’t want an entity per mesh; I have a lot of meshes. I want to just send calls to the GPU to draw the meshes.
Is this a reasonable thing to want? If it is, how should I try to solve it, and if it isn’t, what should I be doing instead?
The fact you don’t want an entity per mesh makes it hard for me to suggest a solution. Either you are afraid something is too expensive without actually profiling it, or there is something about your problem I don’t know about that would make a bunch of things I’d suggest moot.
Can you provide a little more background into what you are trying to solve? Also, how big is your appetite for really low-level complex APIs?
1 Like
It just seems, intuitively, that I have all these meshes that aren’t attached to any entities yet. I could attach each of them to one entity and end up with a bajillion entities, all doing the exact same thing, all different in exactly zero ways. Or I could attach them all to one entity that just draws them. The latter just feels like a cleaner solution to me, if it’s something that can be done without suffering.
No, I haven’t profiled it; I haven’t even gotten it working in ECS. It’s more about how I want to solve the problem than what’s the absolute most performant way to solve the problem. If I’m asking how to fit a Rubik’s cube into a circular hole, I’ll switch to just making a bajillion entities.
That was a really long-winded way of answering one question. What I’m trying to solve is I just want to draw meshes. I have a bajillion (at least 8000) because I wanted to rip off Minecraft and I set the chunk visibility radius kinda high (>=10, 3d chunk grid). And I enjoy really low-level stuff, actually, but I’ve failed to understand a complex API or two over the years because I couldn’t figure out the documentation.
Is the mesh really the only thing that would be different between these entities? What about their position offsets? What about their bounding boxes for culling? Do they have different materials?
If they truly are all the same, then why do have a bunch of different meshes and not just one combined mesh?
If you want to get away from entities, your options are to either use Graphics.DrawRenderersInstanced(), or dive into the very low-level BatchRendererGroup API. The latter is extremely fast and very customizable, but also requires a significant amount of work to get fully up and running and reap the benefits.
1 Like
You’re right, I didn’t even think about position offsets/bounding boxes. Whoops. I’ll check out that method and API, but I’ll probably go with a bunch of entities. Thank you.
I once created an experimental Minecraft-like terrain using ECS. I backed a terrain mesh chunk entity with an empty placeholder mesh as an entity prefab. Then I instantiated that prefab, replaced the mesh, and updated the bounding box.