Limiting character count

Can we limit the number of characters entered into our dialogue node? Basically, I’ve had issues where I’ve typed up a dialogue that is too large to be displayed in the textbox on the screen, as such I’m looking to see if there is a way to have our Dialogue Editor either have a max number of characters per node or change colours to let you know that you have gone beyond the limit of what can be displayed in a box.

I know this is a little outside of what is taught in the course, but if anyone has any great suggestions I’d love to hear them.

1 Like

In the course we used


You could try to instead use


It has an overload that takes in the max length. I haven’t tried it myself, though. May not work as expected

1 Like

Not sure how well GUILayout.TextArea() would work in our custom Dialogue inspector. Plus, nothing stops you from editing the text field in the DialogueNode’s inspector.

What we can use instead is the OnValidate() method within DialogueNode.cs. It works with both the standard inspector and our Dialogue Editor. Add this to your DialogueNode.cs, and be sure to create the maxTextLength integer variable with your desired maximum length.

        private void OnValidate()
            if (text.Length > maxTextLength)
                text = text.Remove(maxTextLength,  text.Length-maxTextLength); //Edited wrong order of operations

Really like this approach, though it did initially cause an error due to the order of the maths.

text = text.Remove(maxTextLength, text.Length - maxTextLength);

This seems to be the way to have it work without causing any errors.

Thanks again, really appreciate the help.

1 Like

LOL, sometimes when I type in the script on the fly, mistakes happen. I edited my response to make myself look smarter. :slight_smile:

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms