Level of Detail management (LOD)

Hello,

I don’t really try (just a few yours) Unity, but I searched in documentation and forum and I didn’t find anything on how LOD is managed.

My app can contain 15 to 30 same characters with 5000 vertices. Of course, I don’t need really 5000 vertices if some characters are far away.

Should I have several models with different LOD, and import in Unity3d or something different ?

If Unity is capable to optimize the management of the character if it’s the same character in the scene ?

Sorry if I missed the information in the doc.

Thanks,

Twin

Yep. The terrain engine has built-in LOD, but aside from that it’s up to you how you want to manage it. (Which is for the best since it varies depending on what you’re doing.)

–Eric

There’s no built-in LOD for characters. However, it’s quite easy to build multiple LOD versions of character meshes, and have a script dynamically change the mesh used based on the distance.

Like Eric5h5 says, there’s tons of totally different uses that people use Unity for, and a classic FPS-style LOD system might not be suitable for everyone.

Thanks for the response.

So, If I have 20 characters,
on each Update(), I have to calculate the distance from the characters to the Camera and switch between a high and a low detailed model. By switching : I mean instanciate a new GameObject or it’s better to create first 3x20 characters (3 for 3 levels of detail) at the beginning of my game and switch between after during the Update().

Do someone has already manage LOD with several characters/models in Unity3d ?

Thanks for your advice,

Twin

No need to instantiate lots of objects or replace the objects. You can just change the mesh that is used in the MeshFilter component. Something like this (a very simple example with two LODs for clarity, assign meshes to be used in the inspector):

var highLod : Mesh;
var lowLod : Mesh;
var distance = 10.0;

function Update ()
{
    var campos = Camera.main.transform.position;
    var meshFilter : MeshFilter = GetComponent(MeshFilter);
    if( (transform.position - campos).sqrMagnitude <
        distance * distance )
    {
        // use high LOD
        if( meshFilter.sharedMesh != highLod )
            meshFilter.sharedMesh = highLod;
    }
    else
    {
        // use low LOD
        if( meshFilter.sharedMesh != lowLod )
            meshFilter.sharedMesh = lowLod;
    }
}

I think someone did use model switching similar to the above. Don’t remember who…

1 Like

Ok,

I’m not very familiar with the MeshFilter but according to the doc, it shows or hide Meshes.

If I use your code, if some characters are running, the
switch between LOD will stop the current animation, because it’s not the same GameObject ?
Am I wrong ?

Tw<in

All it does is changes which Mesh is used to display a character. The game object is not changed or switched at all.

So animations should just work, scripts should continue running and so on; all it does is changes which mesh is used.

When you talk about the update() function, is it the update function linked to each GameObject ?

Because my app should create dynamically the characters , where definitions and positions comming from a XML file, I can not generate the the content of such an Update() function…

Many 3D Engine propose such a feature, switching LOD with distance parameters, even generating the LOD inside the Editor. I think it should be considered as an enhancement for Unity3d team.

It’s a script (my example above), that you attach to any object that you want to be LODed. So this function will execute on any game object the script is attached to. If you’ll attach it to 20 characters - well, 20 characters will be LODed.

If you will be instantiating those object from prefabs (highly recommended), then just include the script in a prefab. If you’ll be assembling the objects completely from scratch, just add this script to any object you want to be LODed (using AddComponent).

The script above does exactly that (with two LOD levels, but it’s easy to expand)… While I agree that it’s a nice to have feature, doing it manually is also quite easy. And the LOD logic is often very dependent on game specifics.

Thanks for your quick and precise response.

Your solution is perfect for my needs. I didn’t imagine that Unity is so flexible, powerful and well architectured !

This comment closes the post.

For those of you googling and come across this post. I have made a LOD script for Characters/SkinnedMeshRenderers:

1 Like