How to organize your scripts and GameObjects in game developement?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


How to organize your scripts and GameObjects in game developement?



I work with Unity.



My problem is sometime I'm not sure how to organize my scripts in folders and GameObjects in scenes. (gameobjects are basic spatial objects where you put on your scripts, scenes are the rooms for all gameobjects you want to load at runtime).



I am confronted mostly with problems like:



"Do I to create folder based on type of gameObject, then add in all scripts related to these gameObjects?"



For example:


Cameras
↳(CameraActivate, CameraFollow, CameraShakeOnReplay)



Or "Do I to create folder based on type of technology, then add in all scripts related to this technology?"


Replay
↳(ReplayTimeline, ReplayControl, ReplayShakeCamera)



Are there rules for this kind of thing?





There's probably some conventions specific to unity for this, but what you are generally speaking of is called Cohesion en.wikipedia.org/wiki/Cohesion_(computer_science) which is the "measure of how well elements inside a module belong together". This strongly relates to OOP en.wikipedia.org/wiki/Object-oriented_programming where you want to keep everything related to a single 'object' or 'class' grouped together. To answer your question I would group everything by the object or thing they operate on.
– user6567423
2 hours ago






2 Answers
2



The short answer is: no, there are no rules.



Here you have a good answer explaining about the folder structure: Is there a standard/recommended directory structure for Unity projects?



About the scene hierarchy, the base I usually use is:


Cameras
├── ...
UI
├── ...
Managers
├── ...
Scenery
├── Static
│ └── ...
└── Non-static
└── ...



But it really depends on the project.



Take a look on this post in Unity blog about how to optimize your hierarchy: Spotlight Team Best Practices: Optimizing the Hierarchy. It has some good practices to follow when organizing the scene:



Hierarchy Structure Guidelines



If something moves every frame, make
sure all its children care about position. Only rendering, physics,
audio, or core systems like that should be there.



When dynamically
creating game objects at runtime, if they do not need to be children
of the spawner for the above reasons, spawn things at the root of the
scene.



You can easily register everything you spawn and pass along the
ActiveInHeirarchy state of the spawner using OnEnable and OnDisable.



Try to group your moving transforms such that you have around 50 or so
GameObjects per root. This lets the underlying system group your
TransformChangeDispatch jobs into a fairly optimal amount of work per
thread. Not so few that the thread overhead dominates; not so many
that you are waiting on thread execution.



Yes, Generally you make a Scripts Folder and put all code files In it. For Game Objects you might be thinking of a Prefab Folder (Look Up Prefab)






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

C++ virtual function: Base class function is called instead of derived