What exactly is the <T>?

I Googled a bit and got type parameter. Is that a data structure? Is it related to supertype or subtypes?
(all this jargon can be confusing)

Is it related to method overriding and virtual methods?

Here are some links that might help you understand what <T> refers to.

I’m gonna tell you something I’ve recommended to a lot of students that are in a similar situation to yours. Take any of the Unity beginner courses before heading deeper into the RPG course, the RPG series only gets tougher, and if your programming foundation is off you are going to have a lot of issues down the road. I’m telling you this because I’ve seen you ask a lot of basic stuff that you should know how to use by now (not necessarily how it works in the background), with by now, I mean when taking the RPG series.

This is a good example, you shouldn’t necessarily know what a generic type is or how to code your own methods and classes with it, but you should at least know what it means when you see it. This also makes helping really hard, because if you don’t get what a type is, How am I supposed to tell you what a generic type is? You have to understand basic types first, and it seems like you don’t understand that yet. This is explained during the beginner courses, that’s why I recommend taking any of those, and if you have taken them, retake them.

I’m not saying you shouldn’t ask questions, on the contrary, please do, everyone here is more than willing to help as you have probably noticed. I’m just trying to save you some potential frustration, you haven’t even got to the saving system yet and that section can get really tough even for intermediate programmers, it even has a warning that asks lower-end of intermediate programmers to skip it.

I found those documents before posting, but they were a little technical for me.

I have done one beginner course (The 2D one) and I don’t recall even touching on any of this. I’ve also done the Unity Learn course and other programming courses, so I am confused.

What do you precisely recommend?

Just from what i observed you asking, it seems to me;
you are asking questions which someone in the RPG course should not be asking.

I think there are a few people who replied to you, who agree with his.
Thats also why i recommended you in another post you made, to do the 2d/3d course,
after that: when you have a better understanding of the basics, get back to this course.
Also just complete it in order, have patience, do the challenges presented,
which are a huge part of the learning process.
Programming isnt something you learn in a few weeks.

1 Like

I’m still learning new things after 40 years!

Like Jeopardy, it’s important sometimes to get the question right…

I’ll give you an example of a Generic parameter that might help demystify things a bit, and it’s something that you’ve used many times before…

public T GetComponent<T>() where T : MonoBehaviour

This is a simplification (actually partially incorrect) of the header for a method that retrieves a component from a GameObject.

The T in this declaration is a Generic Parameter. This means that the parameter is not known at the time that the method is written. This allows us to call this method to retrieve any class, in this case with a restriction that the class must be a MonoBehaviour.

This is why you can use the following syntax:

Health health = GetComponent<Health>();

If you look at the above header for GetComponent, you’ll notice that the return type of the method is T, and the T is also mentioned between the brackets… So if you use Health between the brackets, then GetComponent will locate a T on the GameObject. This makes the method extremely versatile. T could be a Fighter component, or an ActionScheduler, or any type of component that can be attached to a GameObject.

Another commonly used example is in the List class

public class List<T> IEnumerable
{
}

We don’t think too much about what’s going on behind the scenes with a List, and that’s fine, what we do know is that we can put any class or struct in place of the T when we declare a List, and it will work… we create an instance of this Generic class by specifying the Type which T will represent.

List<int> listOfInts = new List<int>();
List<string> listOfStrings = new List<string>();
List<InventoryItem> items = new List<InventoryItem>();
2 Likes

I’ll tell you how I learned how to code, and perhaps, more importantly, how I learned to read the documentation to become independent and not get stuck in the infamous “tutorial hell”.

I learned the basics when I was a kid, like 20 years ago or so, I did it without any tutorial, without any book, and without any documentation. I’m not a genius, I simply practiced a lot. I copy-pasted and simply hoped for the best, little by little, and copy-pasting line by line, I started to understand what each line did to the point I was able to create my own games. At that time I was very consistent, so it only took me 3 months or so to be independent.

That’s the key and what a lot of students miss, you need to practice, not just take the courses, at this point in time you should be able to create your own games, please do that, and if you have any of the beginner courses, retake them and make each project your own, or even better, grab the concepts of each section and create your own game out of that, you can very easily create a racing game with the project boost code, you literally just need to modify the direction of the force, and that’s just one example.

That’s my recommendation, don’t get fixated on learning how certain things work in the background or what they mean, just use them, because the more you use them the more you’ll learn how they work and what they do, but if you just rush through courses thinking you’ll be able to create your dream game after that, you are going to hit a wall, and what a lot of people do when that happens to them is to take more courses, rush through them and hit the wall again, that’s tutorial hell, and the only way to get out of it is to practice.

You might be thinking that I didn’t tell you how I learned how to read the documentation, but I did, you need to practice, to make your own games, I know that sounds weird, but it works, the more games you make the easier everything becomes, that includes understanding technicalities, I suppose that happens because the more games you create, the bigger they get, and the bigger they get the more you need to know so you force yourself to learn new things at a deeper level.

Hope this helps in your game dev journey.

3 Likes

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

Privacy & Terms