Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question How can I divide responsibilities in Unity?

Discussion in 'Getting Started' started by Ryan1Cooper, May 31, 2023.

  1. Ryan1Cooper


    Apr 20, 2023
    Hello community!
    I have a very general newby question here. SOLID principles state that every class should handle only one responsibility to be easy and save to work with. I would love to make that in my game but I afraid that because Unity call scripts every frame I will mess up something so my scripts grow larger and messier and more confusing every time I add something to the game. How can I divide responsibilities into different classes in different scripts that it would not be overwhelming and terrifying to change them? What abilities do I have?
    I'm sorry if this question feels to general I couldn't come up with something more concrete. Feel free to ask specifying questions.
  2. AngryProgrammer


    Jun 4, 2019
    In my opinion, it's good to wrap thinking around game objects.
    1. They organize your code.
    2. Scripts add new functionality to them.
    3. Prefabs and variants are a very good substitute for inheritance.
    4. You can make easy drag-and-drop references in Inspector.
    5. You can use a singleton pattern to keep GameObject between all scenes (ex. GameManager).
    You have a ready game engine, use its logic.