Unnecessary Init Section

  9. Problems & Solutions No Comments

Issue

You have a component that derives from MonoBehaviour<T…> or implements IInitializable<T…>, but you don’t want the Init section to be drawn in the Inspector.

One possible reason for this could be that the component only needs to receive Init arguments when it is being initialized at runtime using AddComponent, but never when it is attached to a GameObject in Edit Mode. The component could, for example, rely on serialized fields to receive its dependencies when it is loaded as part of a scene or a prefab.

Another reason could be that the component only depends on global services, which you know will always be available at runtime, so you find that showing the Init section is unnecessary.

Solution: Hide Init Section

You can hide the Init section for all components of a particular type by disabling the ‘Show Init Section’ option in the context menu of any component of that type.

Leave a Reply

Your email address will not be published. Required fields are marked *