Hybrid Renderer and the TrailRenderer component

The TrailRenderer is not on the list of things not supported by the Hybrid Renderer, but I guess it’s sufficiently niche to not necessarily appear on such a list.

Anyway, when I convert my TrailRenderer toting objects to entities, they stop trail rendering. Is this normal, or am I doing something wrong?

TrailRenderer is unfortunately not supported by Hybrid Renderer at the moment, so trails not rendering for converted entities is expected.

1 Like

Makes sense. Actually, I suspect the TrailRenderer generates its mesh sometime in LateUpdate, right? If I understand the HybridRenderer correctly, that stateful behavior would basically mean you couldn’t pool the TrailRenderer instances?

I am going to try to roll my own by having a system generate the meshes and render them normally.

I rolled my own trail renderer this weekend that’s compatible with the ECS. It works fairly well.

I am building the vertices in a system during the SimulationGroup and storing them in a DynamicBuffer as float3s. During LateUpdate, I have a GameObject helper get all of the entities with trails from the EntityManager and I use DynamicBuffer.Reinterpret and ToNativeArray to get the vertices out and pass them to a Mesh. I render the mesh directly with Graphics.DrawMesh(). It doesn’t have all the features of the TrailRenderer, but it actually works quite well for my purposes.

The only thing that bothers me is that I need to keep creating new Meshes every frame, which is pretty expensive (rendering all the trail takes about 10 ms currently).

I would like to cache the Meshes between frames, but then I’ll have to do more work to expire meshes when the corresponding entity is deleted. I am thinking of running a background job every now and then to build a list of Entities that no longer exist, and whose trail meshes can be expired.

If someone else finds this in the future and has any questions, lay them on me.

2 Likes

Make a triangle strip with as many steps as you would like the trail to have, and just update the vertex positions through a vertex shader?

I think there are some other potential problems with what you’re suggesting, but the first one to occur to me is that such a trail would only render, if the straight mesh (before the shader) is drawn, which would only happen if Unity thinks the camera can see it.

Also, it’s not obvious that would be either simpler, or faster than just building the mesh on the CPU - it’s not like it’s a lot of work.