Assign an object to a component in editor programmatically

Good day.

I have fallowing object structure:

alt text

The “Ship” object contains a bunch of “Subsystem” components. Three “TwoOnOne” objects is a rooms of the ship. Each room must represent one subsystem (also multiple rooms can represent the same subsystem). I want to write an editor extention for a “Room” component that will load all “Subsystems” from the Ship to a popup and will allow a map designer to just select it from a list. But I need to load subsystems only from this particular Ship. Assign a ship object to each room manually is a bit boring and can lead to some ugly errors if map designer forgot to assign it. So I need a way to assign it in code. Normally in game I write a Start function in a “Ship” component, that just assigns this ship to each room below. Like this:

Rooms = new List<ShipRoom>();
var rooms = GetComponentsInChildren<ShipRoom>();
if (rooms != null)
     foreach (ShipRoom room in rooms)

But in the Editor the Start function doesn’t work. Could you please tell me a Start function analogue that works in editor? I tried to use OnEnable function, but it still doesn’t fire in Editor. May be I do something wrong?

Use [ExecuteInEditMode] Unity - Scripting API: ExecuteInEditMode