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

Resolved How do I exclude components from being baked onto an entity in standalone builds?

Discussion in 'Entity Component System' started by desertGhost_, Mar 9, 2023.

  1. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    259
    Hi,

    I have a number of debugging related components that I want to be baked onto an entity for use in play mode in the editor but excluded from being added to the entity when in a standalone build.

    Is there a way to specify that a component type should be excluded from entities in a standalone build, but still attached to an entity for use in the editor / play mode?

    Thanks.
     
  2. jhelbig

    jhelbig

    Joined:
    Jul 25, 2019
    Posts:
    6
    Would something like this not work?

    Code (CSharp):
    1. public class TestBaker : Baker<TestAuthoring>
    2. {
    3.     public override void Bake(TestAuthoring authoring)
    4.     {
    5.         #if UNITY_EDITOR
    6.         AddComponent<TestComponent>();
    7.         #endif
    8.     }
    9. }
     
  3. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    259
    I tried that and it didn't work. I was thinking that would be how to do it, but since baking happens in the editor I think it gets added regardless.
     
  4. WAYNGames

    WAYNGames

    Joined:
    Mar 16, 2019
    Posts:
    988
    I would look into how the netcode package exclude all graphics component from server only builds.
     
  5. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    259
    Good idea. I'll look into that.
     
  6. desertGhost_

    desertGhost_

    Joined:
    Apr 12, 2018
    Posts:
    259
    Bakers have a method
    IsBakingForEditor()
    for this.
     
    WAYNGames likes this.