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.)
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.
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 ?
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…
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 ?
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.