Hi,
I’m trying to invoke an IEnumerator but it doesn’t get fired.
Anyone have an idea ?
Hi,
I’m trying to invoke an IEnumerator but it doesn’t get fired.
Anyone have an idea ?
invokerepeating is not the same as a coroutine.
you can’t yield for it later on for example or use other coroutine functionality
can you show your code please?
void setRemoteAvatarAtStart ()
{
if(PlayerSpawnController.tmp.Count > 0)
{
int remoteID = int.Parse(PlayerSpawnController.tmp[0].ToString());
foreach (User user in smartFoxClient.GetActiveRoom().GetUserList().Values) {
if(remoteID == user.GetId())
{
Debug.Log("match");
string remoteAvatarConfig = user.GetVariable("avatarConfig").ToString();
Debug.Log(remoteAvatarConfig);
genAvi(remoteID, remoteAvatarConfig);
}
}
}
}
private IEnumerator genAvi (int remoteID, string remoteAvatarConfig)
{
Debug.Log("genAvi");
while (!CharacterGenerator.ReadyToUse) yield return 0;
generator = CharacterGenerator.CreateWithConfig(remoteAvatarConfig);
yield return new WaitForSeconds(2);
while (!generator.ConfigReady) yield return 0;
GameObject go = generator.Generate();
go.name = "Character"+remoteID;
Transform remotePlayer = GameObject.Find("remote_"+remoteID).transform;
go.transform.position = remotePlayer.position;
go.transform.rotation = remotePlayer.rotation;
go.transform.parent = remotePlayer;
go.transform.position = new Vector3(0.0f, remotePlayer.position.y, 0.0f);
PlayerSpawnController.tmp.RemoveAt(0);
}
in the Start function i call : InvokeRepeating(“setRemoteAvatarAtStart”, 1, 1);
what i’m trying is generate an avatar for players in the scene but i have to wait for the generator to finish before generating the second avatar.
I also tried to merge the two functions in an IEnumerator but also not got fired.
If anyone is still looking for this,
I think you’re looking for:
IEnumerator coroutine = getAvi(remoteID, remoteAvatarConfig);
StartCoroutine(coroutine);
No need to necro a 7 year old post…
But honestly, your example is really correct. You can just start the coroutine directly with StartCoroutine. The only reason to assign it to a variable is if you plan to stop it, it which case you would probably use a global variable and not a local variable.