I have a different problem then perhaps. But sometimes when I make a method, usually a private method, I can’t call that method from within the script elsewhere. Just sometimes, mind you. And when I throw a StartCoroutine around it the problem goes away. And in fact I’m having that problem right now. Here’s the code I’m using right now:
It starts out with a click on a button (new UGUI). That click executes the code here. It’s a bit big so suffice it to say the only important line for the purposes of this question is “intializeCurrentMatches();”.
public void TogglePlay()
{
if (!_showingMatches)
{
CurrentMatchesObject.SetActive(true);
_showingMatches = true;
HOTween.Rewind(string.Format("ShowMatches{0}", TeamIndex));
HOTween.Rewind(string.Format("ShowFindNewMatch{0}", TeamIndex));
HOTween.Play(string.Format("ShowMatches{0}", TeamIndex));
HOTween.Play(string.Format("ShowFindNewMatch{0}", TeamIndex));
// refresh the active battles
intializeCurrentMatches();
((ManageTeamScript)ManageTeamObject.GetComponent<ManageTeamScript>()).FeatureTeam(TeamIndex);
}
else
{
CurrentMatchesObject.SetActive(false);
_showingMatches = false;
HOTween.Rewind(string.Format("HideMatches{0}", TeamIndex));
HOTween.Rewind(string.Format("HideFindNewMatch{0}", TeamIndex));
HOTween.Play(string.Format("HideMatches{0}", TeamIndex));
HOTween.Play(string.Format("HideFindNewMatch{0}", TeamIndex));
((ManageTeamScript)ManageTeamObject.GetComponent<ManageTeamScript>()).CancelFeature();
}
}
That code calls a private method with a single line shown here:
private void intializeCurrentMatches()
{
((CurrentMatchesScript)CurrentMatchesObject.GetComponent<CurrentMatchesScript>()).InitializeActiveBattles(Party.PartyId);
}
Here’s the method that is never called successfully. If I step into with my debugger the execution hits the method signature line, but then returns without stepping into the method.
public IEnumerator GetActiveBattlesByPartyId(int partyId, CurrentMatchesScript matchesScript)
{
WWW www = new WWW(string.Format("http://localhost:12527/api/battle?teamId={0}", partyId), null, DirectorHelper.GetHeaders());
yield return www;
byte[] data = Convert.FromBase64String(www.text.Replace("\"", string.Empty));
if (OnGetBattlesByPartyIdSucceeded != null)
{
OnGetBattlesByPartyIdSucceeded(this, DirectorHelper.DeserializeFromNetwork<List<Battleschool.Common.Entities.Contract.Battle>>(data));
}
}
However, if I change that second snippet to the following, then the method in the third snippet executes just fine.
private void intializeCurrentMatches()
{
StartCoroutine(((CurrentMatchesScript)CurrentMatchesObject.GetComponent<CurrentMatchesScript>()).InitializeActiveBattles(Party.PartyId));
}