I have an object that needs to have a child object created and referenced automatically so i don’t have to keep remembering to do it.
How do you do this from edit mode? I tried ExecuteInEditMode but Awake/Start doesn’t get called every recompile so i can’t use those functions to set it up. There is no Initialise method so to speak to check so what should i use to make sure this setup always occurs correctly without intervention ?
You need an editor entry point for this code to run. For example, you could use a MenuItem to add a right-click entry that runs the needed code to create this object and initialise all child objects.
If there’s perhaps some configuration you want to set up first before creating it, then I would make an Editor Window.
Or you could write a custom inspector that has a button to generate said objects. Lots of different ways.
ComponentA has an editor button which i can click to reload everything. I need ComponentB and ComponentC to be aware of this so they receive the event too and do what they need to do. All in Edit mode not Play mode. The problem im having is when/where do you make ComponentB and ComponentC subscribe to events from ComponentA? It’s easy enough to do in Play Mode since i can set them up in Awake but Awake doesn’t get called in edit mode even with the attributes it doesn’t get called every recompile to make sure its subscribed to the events.
They do need to subscribe how else will they know my editor code called an event. Awake/Start doesn’t always run in edit mode and OnValidate only runs when an inspector value changes so where do i subscribe these components to listen for event changes?
I don’t think you’ve understood what i am asking here…I’m asking what method to use to initiate code in the components not what function to use to get references to other components. Like i said I can’t use Start,Awake or OnValidate - there is no initialising function in edit mode it seems.
So you saying ComponentA calls B and C rather than C and B listening to A? That seems messy since some times B will be there other times C or both or neither… so i would have to hardcode every component that could potentially attached…since i made my project more compositionally with little dependency… so A isn’t really aware of components next to it
Well you can compose the necessary implementation via interfaces if necessary. And it’s not messy to check for components, especially not since we’ve had TryGetComponent for years now as well.