- Home /
Code in one function call being executed on multiple frames
I am working on a system to manage screen changes and hiding / showing popups in my game (all within the same scene) and I've run into a strange issue. Right now I have the screen / popup changing happen by hiding the previous screen and then immediately showing the next screen. This should all happen on the same frame, so the player just sees the new screen showing, but in practice most of the time (though not every time) there is a frame where both are hidden. The call to the hide function is literally one line above the call to the show function so I'm really not sure why they're being executed on separate frames. Has anyone ever run into a problem like this before? I don't know if this is relevant but I am using delegates and events to trigger the function call. Below is a sample of my popup manager.
void ChangePopup (GameObject dispatcher)
{
if (PopupManager.instance.currentPopup == Enums.PopupType.Options)
{
currentPrimaryPopup = popups.optionsPopup;
}
// Make sure the previous popup is hidden before showing the new one
HidePreviousPopup();
ShowCurrentPopup();
}
void HidePreviousPopup()
{
if (debugLevel > 0) {Debug.Log("hiding: " + previousPrimaryPopup);}
// Get a list of all the children and disable them. Leave the parent active so the game can find it.
for(int i = 0; i < previousPrimaryPopup.transform.childCount; i++)
{
Transform child = previousPrimaryPopup.transform.GetChild(i);
if(child.gameObject.activeSelf)
{
child.gameObject.SetActive(false);
}
}
}
void ShowCurrentPopup()
{
if (debugLevel > 0) {Debug.Log("showing: " + currentPrimaryPopup);}
// Get a list of all the children and make sure they are enabled
for(int i = 0; i < currentPrimaryPopup.transform.childCount; i++)
{
Transform child = currentPrimaryPopup.transform.GetChild(i);
if(!child.gameObject.activeSelf)
{
child.gameObject.SetActive(true);
Debug.Log("Activating: " + child.gameObject.name);
}
}
// We're done with the currentPrimaryPopup so flag it as the previous popup
previousPrimaryPopup = currentPrimaryPopup;
}
I don't know this for sure, but it may be that the game object activates in the next fixed update but deactivates in update.
Your answer
