in all the tutorials I see… whoever teaches you creates more and more scripts about the player
playermovement
playershoot
bullet
I was asking the experts… why use this practice??? wouldn’t it be better to create a single script with everything inside?? e.g… “player.cs” and I have the data of everything… is it a matter of functionality or practicality??
Lots of small classes with specific, singular purposes are easier to main, scale, debug, and fix in the long term. Huge classes handling multiple things quickly becomes a nightmare.
My projects are full of small classes that encapsulate one, focused purpose. And unsurprisingly, I seldom have to deal with bugs. And when I do, they’re easy to fix.
okokok I read the article I just don’t understand this thing… but forgive me … I ask absurd questions to better understand what I read … if the translator has done his duty … I understand well what he means … and you mean … but here we are talking about a simple player … how does it change ??? if changes also mean movements and jumps, I give up… but there he talks to you about sudden implementations… where you change the structure of the program… then it makes sense… but in creating a videogame it doesn’t happen all automatically??? when I create the player… when I create enemies and more… “solid policies” are automatically executed … I’m wrong??? basically a player or an enemy… do those same and repetitive actions… Sure… scrolling through 3000 lines of code is a nightmare… I agree… but I noticed that for me it would simplify the creation a lot… in my case I have 4 players to choose… each with its own different file in some parts to determine the stats and the game is done… or not???
Edit: To clarify; these are ‘best practices’ and ‘guides’.
Do whatever suits you best.
You could do your entire game in 1 line, if you wanted to: I made a game in one line of code - YouTube
Personally, I’d rather stab myself in the eyes repeatedly than do that.
Ultimately it’s up to you to decide where one script ends and the other begins.
It’s perfectly acceptable for a very simple player controller to encompass movement, jumping, shooting, etc.
But when any of those becomes too large, they should be their own script. And in may cases, any one of these concepts can exist in isolation from the other parts. An inventory is not at all related to movement, thus it should be it’s own component. The players stats also doesn’t care about the inventory or movement, and should be it’s own component.
Some components might care about others (that’s fine), and others just live in isolation and just get told what to do from other components.
I wouldn’t really argue against practice that are the foundations of good, healthy code. And if you don’t understand it now, you will understand in time.
okay but i’m talking about what i read… I understand that what is written in the article… is right… but where there is a team of developers… constantly evolving programs… I don’t know… for example the operating system in general… which continuously provides updates… so I agree with what I’ve read… but in a video game… does it make sense??? when it comes to the little things… what will a complete player have??? 2000 lines??? my question is: united can easily hold a 2000 lines of code??? why do they break up a player?? for a question of “WHAT DID I READ?” or to allow unity to make it run better??? setting aside the manageability and bug fix you mention… excluding this speech… 8000 lines of code in one file… would work like 8000 lines of code written in 90 files???
I’m not questioning what you write… and the second time this happens… I ask my questions to cover my doubts well… do you really think this?? that is, that I think I can confront you or maybe think of countering you by giving you wrong??? if so you really have an intelligence deficit… I don’t believe this… on the contrary, I only think of learning from you who are much more expert than me and what you say is for me a decree of law…
Considering AAA-games can take 5+ years to create, and contains tens- if not hundreds of thousands of lines of code: YES.
The PlayerController in my current project contains 270 lines.
The InputManager for that Player contains 650.
The config-ScriptableObject for it contains another 100
If I need to update the config for my player, I’d rather open the “PlayerConfig.cs”-file, as opposed to opening the “Player.cs”-file and searching for the part that contains the config.
You shouldn’t set these aside, they’re incredibly important to the development of a large game.
I’m just saying there’s no point debating whether you should or shouldn’t.
You SHOULD write maintainable code. You SHOULD write code in a way that avoids bugs. You SHOULD write code that can potentially scale with the needs of the project. You SHOULD write code that can be easily be refactored without major rewrites, or without anything else that uses said coding caring about it.
You generally can’t do any of these with huge, singular scripts.
Don’t be afraid to make lots of scripts. They won’t bite. In fact they’ll be your best friends.
FYI, I’m no expert. I’ve only been coding two years. But following these principles that have been developed by individuals my times more intelligent than myself has certainly expedited my growth as a programmer.
No it wouldn’t. An 8000 line script is likely a mess that is awful to maintain. An infinite number of smaller scripts would be better, more maintainable, and more reusable.
i don’t want to put them aside… and how to tell you don’t think about these matters… i just want to know if unity can handle 800000000 lines of code in one file…
again… if i write a perfect code… can unity handle 3569800000000 lines of code in one file…??? what you say is quite obvious … it is clear that it is better to break up … for everything you say … fix bugs etc etc but I’m talking about manageability
yes, but you didn’t answer my question… pretend that I know what I’m doing… and I can move among 96,000 code requests… UNITY MANAGES THEM AS IF THEY WERE 3 MILLION FILES???
Probably? It’s kind of irrelevant to the points we’re making. You’d be insane to have a script that large.
You’re not, honestly. Bigger scripts are less manageable, even if you think it’s easier to deal with less individual script files. Good file organisation makes a larger number of assets a non-issue.
I think the largest individual script I’ve written was close to 1000 lines, and it’s a nightmare any time I need to go back and fix a bug. Unfortunately Unity’s old IMGUI code API leads to large, messy scripts.
Which is why I like UI Toolkit. I can break up all my UI components into smaller chunks of code.
I don’t know how to express myself anymore… it’s clear that the translator does a bad job… I’m not asking for your personal opinion but a technical fact… the UNITY program can handle a file of even 100,000 lines??? or are there consequences in its management??? I’m not interested in knowing how you would do it… why and how I would do it too… for the same reasons you mention… but I ask for a technical answer not a personal answer…
Like I said, probably. But it’d more than likely run like ass, be full of bugs, waste hours of your time trying to fix anything, and be a nightmare whenever you wanted to add anything, but code is just fancy text that the compiler minces up into stuff the computer operates on one instruction at a time.
Why does it matter? This question is completely pointless. I don’t understand why it has you so worked up.
Unity - and by extensions, computers - just do what you tell it to do. If you write a million lines of code without bugs, good for you.
Unfortunately humans are fallible creatures. That’s why we invented computers in the first place. And why we invented practices in order to make it easier for us to tell computers what to do in a reliable manner.
I’m not sure what the limits are these days and it’s not likely you’ll get a “technical” answer on what, if anything, would break first at such scales. The only reasonable way to answer such a theoretical question is to go try it yourself using your workflow. It shouldn’t be hard to create a piece of code-gen to write-out a code file and see where the breaking points are. Those might be your ide, the compilers on your target platforms etc.
Certainly, it shouldn’t break at any reasonable, practicle and useful scale.
I’m used to doing things the way they should be done for reasons… I have now completed while talking to you I did a test… the rules of movement shoot jump and damage… they were all written in 261 lines of code… and the thing is fresh and clear that I have to check better for a moment…
WE ARE TALKING ABOUT A PLAYER will always do the same actions repetitively… why use a best practice where it’s useless…
with collisions… there are over 500 but they are all identical… 10 lines repeated several times… that’s why I ask… if my player had 4 million unity rows how would it behave??? the changes in my game are irrelevant… i can insert a new level different enemies but the player remains static… upgrade aside…