Search Unity

Editor-Only GameObjects and Components

Discussion in 'Editor & General Support' started by deep_deep, Jan 3, 2022.

  1. deep_deep

    deep_deep

    Joined:
    Aug 10, 2019
    Posts:
    16
    Greetings,

    I'm looking for a way to create metadata gameobjects and/or components that are entirely stripped in the build process. It's for an editor-only tool that I wish to make.

    Requirements:
    1. Leaves zero traces in build.
    2. Data is saved when opening/closing the editor i.e. it is not temporary in the scene (HideFlags.DontSave ?).
    3. As there will be serialized fields, some which may contain a lot of data, the proposed method should not rely solely on conditional compilation to strip away the execution statements (start, update, etc.) in an attempt to reduce CPU overhead. The data should not be included in build,, as it may (1) be huge in size, (2) contain sensitive information.
    4. This data should be able to persist in prefabs and scenes (so scriptable object hackery is not a good solution).

    Essentially, I am looking for what the first sentence said, that's it. If this isn't possible in a simple manner, I am willing to use simple workarounds. No super complicated workarounds that make more effort than worth.

    (Bonus points if the component/gameobject is invisible to the user so it can be managed by tool alone.)

    Thank you!
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    deep_deep and adamgolden like this.
  3. deep_deep

    deep_deep

    Joined:
    Aug 10, 2019
    Posts:
    16
    Cool. Now we're left with:
    1. Editor-only components
    2. (Mega Bonus) Hiding said component/go from the hierarchy so users can't mess it up by accident.
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,929
    I don't think Editor only components are a thing, not from any searching I've done in the past. Short of wrapping the body of the code within the monobehaviour with #if UNITY_EDITOR preprocessor directives.

    Would be a handy feature, though I haven't hit a situation where I've needed it.

    Don't believe you can hide components either. Though you can hide serialised fields with the HideInInspector attribute.

    Is it not possible to do what you want to do with traditional editor code?
     
  5. deep_deep

    deep_deep

    Joined:
    Aug 10, 2019
    Posts:
    16
    It is certainly possible especially with the EditorOnly gameobjects. Would've liked that extra flexibility and aura of mystique though :p