EditorOnly Components

I have created an article, in witch I talk about removing component in build:
http://www.belfiore.ovh/devlogs/build-settings/build-settings.php

But now, I want more, and easyer. I would like to add to every components of unity a checkbox “editorOnly”. Every components with this box checked would be EditorOnly, and deleted on build, and in play mode.

I have tryed to create a new Custom editor extention for all monobehaviour, like in this link:

But I have’nt manage to store a boolean in the components itself…

How could I do ? Is it possible ? Could Unity Add this feature for us ?

Thanks you !

1 Like

Use EditorOnly tag for the game object, and attach components to that object. Those objects are excluded from the build.

There’s no easy way of doing this from the component perspective via checkbox.
You can always just wrap your entire class in the #if UNITY_EDITOR #endif and it logic won’t be compiled to the build.

Empty components are almost free.

2 Likes

I know all of that, I spoke about it in the article.
But I want Editor Only Components specificly.

1 Like

That will involve messing around with assemblies and / or code.

You could in theory make an editor that overrides every editor.
Then draw a checkbox and add data for each scene / prefab / component / gameobject binding (into scriptableobject? potentially).

Then, upon build, via build pre-processing script, strip every one of those components. And after build completes, re-attach those components back (or rollback to the state before the build).

The only problem would be that those components are probably going to lose their data state.
Unless everything is rolled back correctly.

So, My Progress so far:

I Have managed to create a custom editor:

first, Having an custom editor for every component is possible, but HARD:
there are more than 120 components who have a custom inspector. So I have to create a custom editor who call them, then draw my stuff. I have managed to do that… almost.

But there are still a lot of error and specific failure. Like with the BoxCollider, the bound resized tools doen’t work in the scene view when I have my custom Inspector on it…

But any ways… let’s say I made it: I have a custom Editor for every components of unity.
I have my PostProcessing ready to call and delete every component who have this boolean to true. Now the problem is… store this boolean in the component…
Arf I would love to work with the Unity team to implement this kind of features…

I am afraid I am stuck here.
If Some Unity dev guys are wandering here…