Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Possible bug with Rebuild and multiple events

A topic by Scarlet String Studios created Jul 28, 2022 Views: 157 Replies: 4
Viewing posts 1 to 4

Heads up — there might be a bug in STM 1.12.3 (Unity 2021.3.4) that causes events to be missed after calling Rebuild. Try subscribing to OnCustomEvent and testing it with something like this:

void OnCustomEvent(string eventTag, STMTextInfo info)
{
    Debug.Log("Executing event '" + eventTag + "'\nFrame " + Time.frameCount, gameObject);
    StartCoroutine(PauseReading());
}
IEnumerator PauseReading()
{
    stm.Rebuild(stm.currentReadTime, readAutomatically: false, executeEvents: true);
    yield return new WaitForSeconds(1f);
    stm.Rebuild(stm.currentReadTime, readAutomatically: true, executeEvents: true);        
}

And you can use string like this:

This is a test string<e=event1> with multiple events<e=event2>, but the subsequent events won't fire<e=event3> if we rebuild the mesh.

When I tried this in a fresh project, only event1 was fired.

In this particular case, I think I was able to work around it by just using <pause> and Continue() like you're supposed to. But I did run into some weird edge cases where Rebuild was messing things up (actually, I think my mesh was rebuilding because the bounds was changing when the line finished reading out, and that's what caused Continue() to not work when I first tried it).

Developer

Ah yeah in this situation, I'm going to say stick to using <pause> and Continue(), or use the delay tag. (<d=10>) to delay by 10 imaginary characters being read out. I'm curious what happens if your custom event calls stm.Pause() and then stm.Continue instead, though? Either way, I think the delay tag might be better suited  for this situation!

Wait, where is stm.Pause() located? I see a pauseCount and a currentPauseCount, but I don't have a method called Pause().

Developer

Ah sorry I was thinking of "StopReadRoutine()" which is a private method. How about... "<e=customEvent><pause>"? So... It calls the custom event that will call continue() on a delay, and pauses at the same time? "Pause" is like... prebaked into how the mesh reads, by the way, just telling the mesh like... "don't bother rendering or parsing the text past this point".

Yeah, that's the workaround that I ended up using. It works, but I think there is a bug buried somewhere in there about Rebuild causing the subsequent events to stop firing.

I was puzzled by this at first, because I think Rebuild was being called by some internal method to recalculate the bounds of the mesh as it was reading out (basically after it read out one line and continued on the next line). It can definitely catch you off guard, because Rebuild is called internally in various situations, and you'd expect that this wouldn't affect subsequent events as long as the read time remains the same.