Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Can a mesh be set up for LOD for all instances before being added to a scene?

Discussion in 'Editor & General Support' started by Mr_Slopz, Mar 2, 2013.

  1. Mr_Slopz

    Mr_Slopz

    Joined:
    Mar 2, 2013
    Posts:
    1
    I'm working on a Unity project, but coming from using Unreal I'm a bit confused by the documentation for LODs in Unity.

    In Unreal I load a mesh into my assets, and then within the options for that mesh I can add LOD models to it. Whenever the model gets placed into a scene it will have the LODs working.

    In Unity the documentation and a YouTube tutorial seem to be describing the process of making a mesh have LOD as inserting a blank object into the scene and then adding multiple meshes into that game object to create the LOD effect.

    In my case I'd want the mesh to already have LOD before being added to a scene.

    To me it feels strange that I click on a mesh and edit various mesh options including the material in the Inspector, yet mesh switching for LOD is not present here and instead appears to only be able to be done when I'm placing it in a scene.

    This seems confusing because I'd want some models to have LOD be part of them the model itself, and used any time they get placed into the scene in the future, and not have to manually set up every instance of a model in a scene using LOD each time.
     
  2. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    I know where you're coming from with your request.
    But Unity let's you do what you are asking for by creating a prefab.
    Follow these steps to setup LOD.

    1. Create an empty gameobject in your scene at X=0, Y=0, Z=0
    2. Add a LOD-Group component to this gameobject
    3. Assign your meshes to the corresponding LOD level of that component
    4. Drag the finalized gameobject to a folder of your Project View to create a prefab
    5. Whenever you want to instantiate your model drag the prefab into the Scene View instead of the mesh

    The only challenge ... or let's call it problem... with this approach: Unity does not necessarily update your prefab if you alter the original mesh. In that case you'd have to recreate the prefab from scratch. A real bummer.
     
  3. RonHiler

    RonHiler

    Joined:
    Nov 3, 2011
    Posts:
    207
    Note that you can have Unity automate that process that Marco has outlined as well.

    In your modeling package, create your three or four LOD levels of your model, with a naming conventions of "Model_LOD0", "Model_LOD1", etc (where "Model" can be whatever you want to call it). Group these models together (in Maya to do this, select all the LODs and hit Ctrl-G). Then rename that parent object as appropriate. So in Maya (as an example) I would have a hierarchy of:

    Corridor
    --Corridor_LOD0
    --Corridor_LOD1
    --Corridor_LOD2
    --Corridor_LOD3

    [Note that it is important that your freeze your transforms for each of the LODs, and that they all have the same origin point. Otherwise they will move around on your when you switch between LODs in-game. The parent object's transform is unimportant, although I also like to keep it's origin point the same as the individual model's origin, and I usually will freeze it as well).

    You then export the group (Corridor) as an fbx file. When you open up Unity, it will set up a group for you automatically with an LOD component on the parent object. Set up the import options on your new group as desired and pull it from your project panel into your scene. You then only need to adjust the percentages on the LOD bar to your liking, and make whatever changes you want (add a collider, audio source, whatever). Then drag that model back into your project panel to create a prefab, which you can then use to create multiple instances of your model over and over again.

    Note that this gives you two items in your project folder, an import controller and a prefab. The import controller will have several items grouped under it, but you can't set any of them, only the import settings on the parent object. The latter prefab object will also have a parent and several objects grouped under it (one for each LOD you made). I generally rename the former as "Model_Mesh", just so I know that is my import settings item and I don't accidentally grab it over my prefab. I also take both those groups and put them into a folder (e.g. Corridor) under my _Meshes folder, just to keep the clutter all organized (you may be able to tell by now I'm big on keeping things organized).

    One last thing that I do that I could mention. If I'm going to add a component that is identical to all the LODs (e.g. I will often add a mesh collider to all four LODs where the collider mesh is the LOD3 [or whatever to lowest detail LOD happens to be]). Instead of adding that same component to all four LOD components of the prefab, I will add it to the parent object instead. I don't know if that helps performance or not, but it helps to keep things tidy in my mind :)

    Doing it this way, I've never had a problem with the LODs. I can make changes in Maya to my models, and those changes (after an export) propagate into my prefabs just fine (and all instances of those prefabs). I've never had to rebuild any prefabs like Marco is talking about.

    Hope that helps.
     
    Last edited: Mar 3, 2013
  4. Marco-Sperling

    Marco-Sperling

    Joined:
    Mar 5, 2012
    Posts:
    620
    I always wondered how this particular passage translated into an actual workflow:
    As it is absolutely not clear from this section of the documentation that one has to export the meshes into ONE fbx file coming from ONE single maya/[any other 3d app] scene.
    Thanks for pointing this out, Ron. This should - as you stated - fix the propagation issue. At least for prefabs that are not nested inside other prefabs.
     
  5. RonHiler

    RonHiler

    Joined:
    Nov 3, 2011
    Posts:
    207
    Yeah, you are right, it's not clear from the Docs :) It took some experimentation to figure out how to get it to work. I wish Unity would put a little more emphasis on clear and correct documentation, maybe throw in some examples here and there. But it doesn't seem to be a real high priority for them. To be fair, it's not an easy thing to do, for sure (gods know I don't do such a great job with documentation either, so I'm not one to talk), but it seems like if they had a full time person who's only job was doing upkeep of those docs, we'd all be better for it.

    But yeah, that's the procedure that I use, and it works pretty well.
     
  6. OmarVectorX

    OmarVectorX

    Joined:
    May 16, 2017
    Posts:
    2
    I've tried this macro now but it doesnt work for adding LOD component automatically, does this feature is removed?
     
  7. bjornsyse

    bjornsyse

    Joined:
    Mar 28, 2017
    Posts:
    92
    This is neat but only seems to work if the child gameobject are the ones actually having the mesh renderers. It does not work if they in turn have children with meshes.