Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Refreshing/updating a component?

Discussion in 'Scripting' started by Dorumeka, Nov 20, 2019.

  1. Dorumeka

    Dorumeka

    Joined:
    Aug 19, 2017
    Posts:
    18
    I'm building a system for swapping the models/skins of my characters at runtime. So far, pretty good on my end, but I've ran into an issue with the LOD Group component. Once I change the LODs on script, and I see that they are correctly set up looking in the inspector, all the LODs are active at the same time. The only way to fix this is to change anything in the inspector. It doesn't matter what I change as long as I force the component to update. As soon as I do that, the LODs magically fix themselves and only the right one shows, while the others are hidden, as you would expect.

    I have tried to call every method and change every property, even waiting frames/seconds using coroutines. Nothing I do on code forces that "update/refresh" behavior that changing anything in the editor does.



    Here's a video (somewhat NSFW) of one of my models suffering this issue. At first, you see all 3 LOD models overlapping, which is not ideal. I turn off the two lower LODs by disabling the gameobjects just to show what the model is supposed to look like. After, I change one random property of the LOD Group in the editor, and immediately after, the LODs are fixed and working correctly.

    What do I even do here? I have to mention, updating Unity is not a possibility here. My project is too big and many things will definitely break. I'm using 2018.4.9f1.
     
  2. Dorumeka

    Dorumeka

    Joined:
    Aug 19, 2017
    Posts:
    18
    Anything?
     
  3. Dorumeka

    Dorumeka

    Joined:
    Aug 19, 2017
    Posts:
    18
    Well, for future reference, this is how I just fixed it.

    I updated to the latest 2018.4, which is 2018.4.12f1, and tried something I tried before that didn't work, that now worked.

    On code, after setting the LODGroup component with the new models, I destroyed the component and created a new LODGroup with the same settings. It's a dirty solution, but it works and I'll take it.