Unity to Xenko Conversion Question

I have a project in Unity current that relies heavily on real time procedural mesh generation. Currently I am having some performance issues with GC as well as a few other areas that as far as I can tell is because the version of C# Unity uses. I was looking at what other engines I could possibly use and ran accross Xenko and had a few questions to ensure whether this was the engine I would transition to or not.

  1. Is procedural mesh generation and manipulation possible in Xenko? If it is how difficult is it compared to the Unity pipeline? Is it possible to use vertex colors in proc gen meshes within Xenko?

  2. In regards to proc gen meshes I saw one user had issues with manipulating and assigning a collision mesh that conformed to the proc mesh. Has this been solved? How difficult is it to create a collision mesh that adheres to the proc mesh. Convex hull meshes will not satisfy this issue in my project.

  3. LOD. I saw that the model class can utilize several meshes for LOD but the roadmap lists LOD details being a possilbity in spring 2017 that isn’t implemented. What LOD functionality is currently built in and working in Xenko?

  4. Lighting. I am no lighting guru so was curious how grossly different the lighting is in Xenko vs Unity built in non baked lighting.

  5. Shaders. I have not delved into shader programming much at all and so was curious how Xenko handles shaders in comparison to Unity. Any notable differences would be great.

  6. Does Xenko have a built-in vertex coloring shader?

  7. Multi-Threading. Does Xenko play well with multithreading? Will I have the same engine contraints in Xenko that Unity has in regards to what can and cannot be multithreaded. Does Xenko help with the mulitthreading or is all manual?

I have a good bit of experience here so I’ll try to lend what advice I can.
Also sorry this is such a long response. Or maybe that’s what you were hoping for :smiley:

1.A) Procedural mesh generation/manipulation is possible. Both engines have rather similar pipelines for it so no huge difference in difficulty. Xenko has you define a struct Type for the vertex to contain whatever data you want per vertex (normal, color, texture, etc) whereas Unity uses separate arrays for each data component.

1.B) Xenko gives you direct access to the low level buffers used to send mesh data to the GPU. This is good because it allows you to reuse those large arrays and reduce GC pressure, but it can be tricky to decipher how that low level API works and to use it correctly. Unity doesn’t let you do this, which makes it simpler but causes GC problems. However, I did recently discover that they have SetVertices/SetColors/Set[T] methods that take List parameters containing the data. I suspect those methods are actually meant to let you do something similar to reusing the buffers. IE make a List with a large initial capacity, fill it with data, use the SetWhatever method, clear the List (but don’t call Trim!) and then you can fill it with data again for another mesh, thus avoiding GC by not having to constantly make new arrays. I haven’t actually tried this though so I might be horribly wrong. Unfortunately their documentation on these methods is awful.

1.C) You can use vertex colors. You can see such working on my Project Voxelscape post / right here; https://www.youtube.com/watch?v=whJOtux2DrQ. Technically it’s supposed to have some pixel textures too, but I didn’t get both vertex coloring and textures working in the shader. Should absolutely be doable though, I just can’t write shaders >.<

2.) Never resolved / can’t do it. BulletSharp has a type that should be appropriate for it but it is not supported by Xenko. You would either have to implement said type yourself and hope the Xenko team accepts your pull request or ditch their physics engine entirely and try integrating something like BulletSharp or BEPUphysics yourself. On the other hand, I did some testing with Unity3D and it looks like they do support accurate physics collisions against procedural meshes, with some caveats of course. You can do physics of simple primitives against a non-convex mesh, but you can’t do non-convex to non-convex. IE you can have a player/creatures whose collision is a simple capsule and some crates you can push around and those sorts of things can collide with the environment, but you couldn’t have 2 proc gen’d meshes collide accurately like say 2 large spaceships. You’d need to use some other trick to simplify the collision.

3.) Got nothing here for Xenko or Unity. Been working on implementing my own LOD system where the mesh generation system and produce simpler meshes for LODs.

4.) Also not a lot to say. Both engines support real time lighting with dynamic shadows, both cast by and onto procedural generated meshes. Pretty awesome not having to implement a Minecraft lighting engine lol.

5.) Xenko has it’s own special flavor of shaders where you compose them out of different smaller pieces of shaders. Looks like Unity3D moved to some sort of Standard Shader model as well to make it easier. As mentioned before though I can’t shader so ¯_(ツ)_/¯

6.) Yes, but I’ve only figured out how to make it either do lighting + vertex colors or lighting + texture. I’d like to do all 3 together, but in a rather particular way… Pretty sure it can be done, but… shaders…

7.) Xenko has a built in notion of an AsyncScript. As I understand it it lets you call into async code and then when you need to get back onto the main thread you can just await Script.NextFrame() and it’ll marshall you back into the main loop. Super easy to use. Beyond that the engine has some built in multi-threading to help improve performance, but if you’re doing any really stressful work like say generating a bunch of voxels or procedural meshes you’ll likely want to do that on background threads yourself. Similar restrictions apply in Xenko like they do in Unity, such as not being able to modify game objects on background threads. That’s just an inherent limitations of just about any UI framework / game engine. The big benefit of Xenko though is that it’s modern C#, meaning you can uses Tasks, async await, TPL Dataflow, Reactive Extensions, Concurrent collections, Immutable collections, all sorts of amazing stuff. Being stuck to C# 3.5 in Unity was awful for multi-threading…

This reply has gone on plenty long already soo maybe write back if you wanna hear more about anything in particular.

1 Like

Thanks for the in depth reply. Am I understanding you correct that you are having issue with Vertex Colors + Texture + Lighting shaders? Do you think it is an engine limitation stopping you or just lack of shader knowledge?

You are correct. Xenko comes with a bunch of shaders out of the box that you can apply to your material. This includes one that will support textures and lighting, or one that supports vertex colors and lighting. BUT you can also compose your own shaders too, so it’s not at all a limitation of the engine, it’s simply my not investing time to learn shaders yet.

Xenko vs Unity3D is a tough choice. I will caution, going with Xenko means having to figure out most stuff out for yourself. I know they’re working on more documentation and tutorials, which is definitely good, but Unity3D already has a massive amount of tutorials and examples out there for a beginner developer to learn from and tons of people on their forums.

Before switching engines it would be prudent to make sure you’re doing what you can to fix your performance problems, because if it’s problems in your own code then those issues will continue to haunt you regardless of what engine you use. Unity’s GC gets a lot of criticism, but when I first ported my voxel engine to both Xenko and Wave Engine it still performed awfully. It’s important to reduce GC by reusing large arrays where possible and to avoid reallocating and copying data repeatedly. It’s important to take large amounts of number crunching off the main thread and then marshal results back. But great care has to be taken to do these things correctly and so much more. I’m even reevaluating Unity again now.

The documentation has gotten much better now. Also since version 3, Xenko has gone to MIT open source. Not to mention even more shader and physics improvements and more features.

1 Like