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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

LODGroup on moving objects

Discussion in 'Editor & General Support' started by paulindrome, Aug 29, 2019.

  1. paulindrome

    paulindrome

    Joined:
    Mar 10, 2018
    Posts:
    30
    In my scene, LODGroups on moving objects are not calculating the appropriate LOD level correctly.

    I have a bus of sorts that runs a pretty long animation that takes it across a vast cityscape within about a minute or so. When I stand along its route in playmode (first person camera), the LOD stays at level 4, disregarding the actual currently shown screen size of the renderer.

    When I pause and check what's happening, the localReferencePoint of the LODGroup is somewhere in the air.
    When I manually recalculate the bounds of the LODGroup, the level adjusts correctly only but only to the current position.

    I have two theories:
    1. LODGroups on animated objects have some trouble when the camera is in a different scene from the group or there are multiple cameras active. There is a minimap camera far above the scene following the player position. But in that case, how do I get the LODgroup to work with the correct camera?
    2. LODGroups on animated objects internally have a distance comparer of some sort and prioritize their calculations around that somehow. I have tried various different ways of setting up the LODGroup on the object (subgroups for individual humans in the bus and for the bus itself or all renderers in a single top-level LODGroup) but none seem to have the desired effect. Should I set up a specific root object in the model import settings as well?

    EDIT:
    Apparently, putting the LODGroup component on an object in the hierarchy whose position is animated as well fixes the issue. This is weird to me because I was under the impression that LODGroups work SOLELY on the screen size of the calculated bounding box of its renderers.
    Is there some sort of internal Unity function that tells an LODGroup component to update its calculation only when the Gameobject's position changes?
     
    Last edited: Aug 29, 2019
  2. paulindrome

    paulindrome

    Joined:
    Mar 10, 2018
    Posts:
    30
    Bump.

    It seems LODgroups don't exclusively work off the size of a renderer's bounding box. Is there anything under the hood?
     
  3. donadagames

    donadagames

    Joined:
    Oct 2, 2020
    Posts:
    2
    I was having the same issue with my project for enemies walking around. I fixed it by add all scripts and all components (LOD group, colliders, rb, animator, ...) in the parent game object... As the child objects now I just have the mesh renderers objects, etc.

    I think if you split the movement script, and put all code that moves your object in to the parent (with the LOD group) object.. It will work.

    You want your parent object (with the LOD group) to be moving, not just the LOD renders (LOD0, LOD1, LOD2 ...). If the parent object (with the LOD group) moves, the camera perception of distance will follow it.