Page 1 of 1

Menu Text and Dialogue Text -> ArgumentOutOfRangeException: Index and length must refer to a location within the string.

Posted: Sat Mar 23, 2024 5:29 pm
by hellohello
Hello, maybe someone stumbled across similar issue. I sometimes get this " ArgumentOutOfRangeException: Index and length must refer to a location within the string." exception on some nodes regarding text from Menu Text/Dialogue Text.

The consequence is that dialogue/menu text from specific node is not being written (I use typewriter textMeshPro effect). It however shows up as already written, when the next node is being written "by typewritter".

I can't find the connection why it is happenning. I first thought, that it happens, when text from Menu Text and Dialogue Text have the same length, but it is not always the case.

This is full Exception:


ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Parameter name: length
System.String.Substring (System.Int32 startIndex, System.Int32 length) (at <bfbc89a04b6b4dd49c3614d03fc31ce8>:0)
PixelCrushers.DialogueSystem.TextMeshProTypewriterEffect+<Play>d__40.MoveNext () (at Assets/Editor Default Resources/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Utility/TextMeshProTypewriterEffect.cs:245)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <f7237cf7abef49bfbb552d7eb076e422>:0)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
PixelCrushers.DialogueSystem.TextMeshProTypewriterEffect:StartTypewriterCoroutine(Int32) (at Assets/Editor Default Resources/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Utility/TextMeshProTypewriterEffect.cs:233)
PixelCrushers.DialogueSystem.TextMeshProTypewriterEffect:StartTyping(String, Int32) (at Assets/Editor Default Resources/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Utility/TextMeshProTypewriterEffect.cs:204)
PixelCrushers.DialogueSystem.TypewriterUtility:StartTyping(UITextField, String, Int32) (at Assets/Editor Default Resources/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Utility/TypewriterUtility.cs:47)
PixelCrushers.DialogueSystem.StandardUISubtitlePanel:SetSubtitleTextContent(Subtitle) (at Assets/Editor Default Resources/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Standard/Dialogue/StandardUISubtitlePanel.cs:626)
PixelCrushers.DialogueSystem.StandardUISubtitlePanel:SetContent(Subtitle) (at Assets/Editor Default Resources/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Standard/Dialogue/StandardUISubtitlePanel.cs:582)
PixelCrushers.DialogueSystem.StandardUISubtitlePanel:ShowSubtitleNow(Subtitle) (at Assets/Editor Default Resources/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Standard/Dialogue/StandardUISubtitlePanel.cs:292)
PixelCrushers.DialogueSystem.StandardUISubtitlePanel:ShowSubtitle(Subtitle) (at Assets/Editor Default Resources/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Standard/Dialogue/StandardUISubtitlePanel.cs:278)
PixelCrushers.DialogueSystem.StandardUISubtitleControls:ShowSubtitle(Subtitle) (at Assets/Editor Default Resources/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Standard/Dialogue/StandardUISubtitleControls.cs:511)
PixelCrushers.DialogueSystem.StandardDialogueUI:ShowSubtitleImmediate(Subtitle) (at Assets/Editor Default Resources/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Standard/Dialogue/StandardDialogueUI.cs:276)
PixelCrushers.DialogueSystem.StandardDialogueUI:ShowSubtitle(Subtitle) (at Assets/Editor Default Resources/Plugins/Pixel Crushers/Dialogue System/Scripts/UI/Standard/Dialogue/StandardDialogueUI.cs:242)
PixelCrushers.DialogueSystem.ConversationView:StartSubtitle(Subtitle, Boolean

Re: Menu Text and Dialogue Text -> ArgumentOutOfRangeException: Index and length must refer to a location within the str

Posted: Sat Mar 23, 2024 5:48 pm
by Tony Li
Hi,

I'm traveling from GDC today so I can't send you an official, tested patch just yet. Please try changing line 245 of TextMeshProTypewriterEffect to:

Code: Select all

if (0 <= fromIndex && fromIndex < textComponent.text.Length) fromIndex = StripRPGMakerCodes(Tools.StripTextMeshProTags(textComponent.text)).Substring(0, fromIndex).Length;

Re: Menu Text and Dialogue Text -> ArgumentOutOfRangeException: Index and length must refer to a location within the str

Posted: Sun Mar 24, 2024 7:08 pm
by hellohello
Thank you, that you posted your reply even when travelling!
What i found is, that when I am turning off Typewriter Mesh Pro component, everything works fine, so indeed,this is a problem specific to Typewriter.

I tried your solution, but it doesn't change the situation.

I tried to narrow the problem - now it occurs in the part of conversation, where (Player and NPC)
Player gets six flavours and must guess, which three of them are the NPC's favourite. After he chooses any answer, he gets NPC's unique-to-flavour response and goes back to the menu of six flavours (there is SIM status checked, and chosen answer goes away). So he keeps on guessing, and when he chooses three right, the conversation goes on about making a pie.

So the typewriter "breaks" in this "six flavours" area. It specifically breaks after NPC's unique-to-flavour response, and it's like random. Then, rest of conversation also breaks. It seems like it has a problem with getting back many times to the same node, or maybe it is just mine impression.

Re: Menu Text and Dialogue Text -> ArgumentOutOfRangeException: Index and length must refer to a location within the str

Posted: Sun Mar 24, 2024 10:06 pm
by Tony Li
Hi,

I think replacing line 245 with this should address the issue:

Code: Select all

                var stripped = StripRPGMakerCodes(Tools.StripTextMeshProTags(textComponent.text));
                if (stripped.Length > 0 && 0 <= fromIndex && fromIndex < stripped.Length)
                {
                    fromIndex = stripped.Substring(0, fromIndex).Length;
                }
If not, please let me know the following:
  • Is your subtitle panel's Accumulate Text checkbox ticked?
  • If so, what is an example of the text that is already shown in the panel and the text that is about to be typed out?

Re: Menu Text and Dialogue Text -> ArgumentOutOfRangeException: Index and length must refer to a location within the str

Posted: Mon Mar 25, 2024 1:05 pm
by hellohello
Hello!

I used your snippet and it partially solved the problem.
Yes I accumulate text and I also use greying out previous dialogue sentences (Script from this forum).

So before, when dialogue started to break:
-some lines weren't typewriting, and afterwards they were showed as grey, when next node was being typewritten.

Now after code fix:
in this "breking area", lines are shown "as typewriter effect was off". So they are shown in colour and in order, but without typewritter effect. And this also breaks next lines in terms of typewriting, just very long sentences are typewritten - specifically just ending of them

When I turn off "accumulating text" checkbox it indeed works without problems.

Examples (it is in Polish :)

Typewritten: "Proszę zgadnąć! Co lubi taki elegant jak ja?"
about to be typed out: "To może"

I saw, that this short text "To może", is the first that is not typed out. It is short, though, but before in dialogue even short words are typewritten. After that, it seems, that gradually longer and longer nodes are not typed out, and finally nothing is typed out with typewriter effect. What is also specific about this - after "To może" it is the first time we get six options of flavours.

Re: Menu Text and Dialogue Text -> ArgumentOutOfRangeException: Index and length must refer to a location within the str

Posted: Mon Mar 25, 2024 4:55 pm
by Tony Li
Hi,

Are you using the current version of the Dialogue System (v 2.2.44.1)?

Re: Menu Text and Dialogue Text -> ArgumentOutOfRangeException: Index and length must refer to a location within the str

Posted: Tue Mar 26, 2024 4:53 pm
by hellohello
Yes, but few days ago, I indeed migrated my project from one computer to another.
I will try to built it from scratch and see if the issue exists.