I have a function that serves two purposes. It returns the SiblingIndex of a specific GameObject, and it sets another GameObject to active if the activateHeading parameter is set to true. Below is a snippet of this function.
public int GetSiblingSlotIndex(DataObject d, bool activateHeading)
{
...
switch (d.GetFeatureType())
{
case FeatureType.Heading1:
if (activateHeading)
{
Heading1.SetActive(true);
}
return Heading2.GetSiblingIndex();
...
}
The problem I’m having is that the Heading1 object will not be set to active (or at least, will not have its Awake() function called) until the rest of the code has finished executing. Here’s a simplified example of what I’m talking about:
public void CallSiblingSlotMethod(DataObject d)
{
int index = GetSiblingSlotIndex(d, true);
Debug.Log("Finished getting slot index");
}
//[Inside the Heading1 class file]
void Awake()
{
Debug.Log("Awake() called");
}
With the problem I’m having, if I were to run CallSiblingSlotMethod(), the output would look like this:
Finished getting slot index
Awake() called
Is there any way to force the program to wait for Heading1’s Awake() function to finish before moving on? I’m aware that coroutines could probably be used to achieve this, but I’m not sure how to incorporate them into my existing code.