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

Question Strip Parts of Scene On Build

Discussion in 'Editor & General Support' started by deep_deep, Sep 15, 2022.

  1. deep_deep

    deep_deep

    Joined:
    Aug 10, 2019
    Posts:
    16
    Is it possible to process a scene right before it's queued to be built without modifying project files?

    Essentially, I have some scenery and props that is combined using MeshBaker and saved as a GameObject instance in the scene. I prefer this workflow instead of creating tonnes of small prefabs.

    The GameObjects used for baking are disabled in the scene, and the result is enabled, so everything works from a gameplay perspective. However, these objects (and any referenced meshes/textures) are still included in the build, bloating its size, when I really only need the baked objects.

    There's hooks like OnPostProcessScene, but it both runs when saving scenes normally, and I don't know if changing the scene during the build-invocation of PostProcessScene will affect the scene on file.
     
  2. deep_deep

    deep_deep

    Joined:
    Aug 10, 2019
    Posts:
    16
    https://docs.unity3d.com/ScriptReference/HideFlags.DontSaveInBuild.html

    I understand that this exists. However, it has a scary, unexplained line in the description:
    • You must manually clear the object from memory using DestroyImmediate to avoid memory leaks.
    If anyone can confirm that this is a dumb automatic-documentation thing, I'd be happy to use this.
     
  3. tomfulghum

    tomfulghum

    Joined:
    May 8, 2017
    Posts:
    78
    Last edited: Sep 15, 2022
    Mnemotic, DanjelRicci and Kurt-Dekker like this.
  4. alchemist_wurzelpurzel

    alchemist_wurzelpurzel

    Joined:
    Sep 4, 2018
    Posts:
    43
    In addition to what @tomfulghum said, you could also use the EditorOnly Tag on GameObjects you want to exclude from your builds.