Should You Use Namespaces in Unity?

preview_player
Показать описание


My Favorite Unity Assets 💯⤵️

* Disclosure: These are affiliate links, which means I'll receive a commission if you use them to make a purchase.
Рекомендации по теме
Комментарии
Автор

Now I want to make a game where all of your movement depends on your inventory and what's in it.

samach
Автор

What if the inventory holds an item that effects your movement speed?
I assume you'd make a middleman -- a buff class or scriptable object. But then, there are many types of buffs, so referencing a buffs namespace means importing all that.
What would be your solution to this?

verified_tinker
Автор

I personally wouldn't recommend tight written code like that.
What if you want to have default stats, but then a list of those stats that you change and use, base stats.
Say an item wants to affect your movement. You should be able to make it either multiply based on the default value, or the current base value that's been modified by other items or effects.
Or what if an item/effect causes you to bounce when you touch the ground above a certain speed. Now that needs to know when you touch the ground and affect your falling velocity.

magnusm
Автор

inb4 we find out that the entirety of Skyrim was written within a single class.

infinitefretboard
Автор

Great info, thank you!
Please make a video about DOTS :) You will be a superstar :D

irybas
Автор

I disagree, *movement class* could in some cases have access to *inventory class* in order to keep track of weight that is bearing on the player in order to constrict player movement when a certain weight threshold has been reached or when a certain item acts as a booster to increase our speed or even decrease it as a side-effect. Therefore I would say that in most cases *movement* shouldn't have access to *inventory* but not never. Unless we decided to propagate total weight from *inventory class* down to a variable in a class named *playerstats* for example.

graphics_travelers
Автор

Here's one instance where you would 100% have to access your inventory from movement: if the amount in your inventory affects your movement speed. That said, I understand that creating hard links and tight coupling to make this happen is wrong and that there is a plethora of better ways to handle it (actions come immediately to mind). But that is an instance where your movement system may need a piece of information from your inventory system.

pudgystump
Автор

I never realized how poorly organized my code was...

marscaleb
Автор

Especially now that the newer version of unity helps compile better.

justinwhite
Автор

What about expanding your game's mechanics? Take Diablo 2 for example.
You have an inventory, and your body. You put items on your body and gets the stats. So the inventory and body don't interact. But.
The sequel added a new type of item that do that. It adds stats passively while inside the inventory.
So where does that fit in? Do they know each other or does items have some independent relation to everything else.

magnusm
Автор

I get the idea, but I'm worried that instead of half a dozen scripts I would send up with a library of 100s of scripts and losing track of what is being done in what script. The structure is great, but it's also something to commit to memory, no? You can follow methods to their source, I get that, but I'm just concerned about the 'spread' of the code. Any thoughts about that concern?

Squared
Автор

Are these ideas of boundaries still relevant when programming in ECS? It seems that the separation of data and system is enough to minimize spaghetticode

daslolo
Автор

It's funny but also encouraging that big name games have spaghetti code.
Like saying sure your code is a mess and stupid, but the pros whose made your favorite game might have made it just like you have and it worked.
And it can also mean, if they can make such a great gem with trashy code, then how great can't your game be when you learn those faults? Code better, and make better.

magnusm
Автор

What if.. for example (I'm a noob by the way and am genuinely asking, not trolling!) Anyway, what if the inventry item was a power up and that power up directly affected movement speed for example.. What could you do then to reference the movement speed in the different namespace? would it just be like namespace.movement.class() or what? Cheers for the help anyone who answers :-)

techslugz
Автор

Should have used the proper namespace when googling "Regression", like :))) cause Regression lives in many different namespaces e.g. Statistics, Medicine...

dererzherzog
Автор

Hello, I have a issue about quaternion lookrotation. I want to rotate my objcet fully. But I didn't. I drew a raycast and I said to camera look hit point. I can rotate every where but I cant do somersault to my objcet.Thank you.

misal-isahabe
Автор

Movement has nothing to do with your inventory.



Most of the Diablo-like

tomtomkowski
Автор

What tha hell is that question? I am sick of tired of noob devs who thinks they know better and does things "their way"( if you can call it a "way"). You want answer to that question? Check unity codes. Simple right? They use encapsulation so should you they use properties so should you they use namespaces so should you. Stop being lazy and neglecting things you dont know and fool your self with "i do this way its better" or "i can handle it". YOU MUST USE EVERY THING C# HAS THIS IS YOUR SIMPLE ANSWER. We are code engineers we dont even keep one variable in code if its not used and you come and ask "should i use namespaces" no dont use them we developed it for fun...

BlakeKane
Автор

When are you going to level up more and start using ASMDEF's. Helps devs STOP cyclic referencing!!! And crazy boosts your compile time. I use this instead of namespaces. Its so nice to compile your code and its 2 seconds instead of 10-15 seconds. Takes more time to setup, but when your a full time Unity Dev, and compiling your code 100 times a day, and each time you compile you save 10 seconds. That's 16-25 minutes I wasn't sitting around waiting. One project at work had a 30 second compile time on i9 processors which is now between 5 and 10 seconds.

mikenspired
Автор

"Why in the world would your movement need to access your inventory?"
1. Because of shoes.
2. Because of climbing rope.
3. Because of carry weight.
4. Because of car keys.

paladinrose