Best practices: Text via Unity editor or loading via scripts

Hola,

I am half way through the text101 course and I am wondering something.
Is it good practice to add text directly in the text fields under the inspector panel in Unity? I am wondering if in the long run it might be more appropriate to load all the text on start() when loading the program.

It feels a bit hard coded and eventually having to go through each component to modify text could be a bit of a hassle. I am thinking that loading all the strings from an external asset such an XML file or whatever where you can keep all the texts in one place could be a “better” approach?

You probably discuss this later on, I just wanted to throw it out there and hear your thoughts.

The same goes for assigning assigning states to a state by drag and drop. Doing this programmatically seems more organised and less likely to mistakes.

What ya think?

Hi Kenneth,

Thank you for your questions. :slight_smile:

It depends. If it’s just a heading that does not change, I would not add a script. Furthermore, I prefer to add at least a default text in the Inspector because when working in Unity, I don’t want to open dozens of scripts to see what the purpose of certain elements is.

It is very unlikely that anybody will ever see your fancy code. Your future player want a bug-free game, and that’s it. For this reason, when developing a project, take the time into consideration. Will your project benefit from an XML in the long run or would it rather be a waste of time to implement a rather complex solution for changing the text of one or two components?

That’s right. For a complex game, our current approach is rather subpar. To be honest, I would not use Unity at all for a project like this because Unity is way too powerful, and it’s files way to big for a game that simply shows a few lines of text. The project is nice to become familiar with Unity and programming, bit it has got its limits. If you want to see a program which was created for text adventures, take a look at Twine. Of course, you could use their concepts and apply them to Unity. Alternatively, you could simply use their tool.

In larger Unity games, data binding and localisation could become interesting. Type these two keywords into your preferred search engine to learn more about them. There are various approaches.

If you “just” want to challenge yourself in this section, take a look at JSON. You don’t have to use scriptable objects at all. If you know C#, you could create normal C# objects and feed them with data from the JSON file. If you are interested in a free C# course, I can recommend Bob Tabor’s.

1 Like

That was quick! TY for the reply :slight_smile:
Yes, to learn and for a couple of strings I would never go for an approach like this. Big overkill. I was thinking big projects, like you said.
I am familiar with JSON. Used it to generate classes in Java. That sounds like a great idea.
For now I’ll stick to the program and learn steadily. This was just a thought that crossed my mind.

TY Nina!

1 Like

I’ll be focusing my whole attention on this particular question: “Is it good practice to add text directly in the text fields under the inspector panel in Unity?”

In short, at least from my perspective, yes, it is good practice. Why? Because it gives you flexibility, which is something you want when developing a game, imagine this scenario: You are making a RPG style game and you need each NPC to talk, so you create this XML file, it would be more of a hassle to actually go through that file, change the dialogue, save and so on, it’s much easier to just go to that particular NPC and edit the dialogue in a component.

The more I develop games the more I realize something, when coding you should… well… code, when designing the game you should… design the game, I know this sounds dumb, but what I’m trying to say is that when designing the game you should NEVER go back to your code and viceversa, not even to fix a bug, if you found a bug (that is not completely breaking the game), just take note and fix it later. Why? Because it makes everything a lot easier and more organized, it’s also less distracting and if you are working with a game designer, the designer should not go into the code.

To prove my point here’s a link to an official Unity tutorial that shows exactly what I’m trying to say.

You’ll be creating a 2D RPG, you won’t be coding a single line during the whole process, that’s because the programmer created tools to let the designer do whatever comes to mind, that’s the common approach, you’ll see that they handle quests, dialogue and more with a somewhat similar approach to what Rick does here just far more complex, it’s also a good idea to just look at the tutorial to get ideas on what you can do with Unity, it’s an amazing example on how to develop your own tools to create your own libraries for your future games, saving you a lot of time.

Privacy & Terms