Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by rugved1991 · Apr 15, 2015 at 12:51 PM · design-patterns

How do i implement design patterns in Unity?

Hi,

I am new to Unity and i have been trying out a game. I have made Arkanoid game in 2D using tutorials. But now i am trying to implement design patterns in the game. I am not sure how to use it in unity. I have implemented it before in greenfoot. Please guide me in my problem.

The basic idea of the game is to bounce off the ball from a pad and hit the bricks above to destroy them. When all bricks are destroyed the level is changed. Some bricks when destroyed drop some powers which when collected by the pad changes its behavior.

In what cases can i implement the design patterns. I know i can implement observer pattern to show the score. Command pattern to show the menu screen.

Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DiegoSLTS · Apr 15, 2015 at 01:14 PM 2
Share

You can't implement "design patterns", you have to implement some design pattern. Also, forcing the implementation of a design pattern is the wrong way to use them, a design pattern is something you should use if your requirements and tools allow you to implement it. Some patterns don't even make sense in Unity, so be more specific, what pattern do you need?

avatar image Owen-Reynolds · Apr 15, 2015 at 02:39 PM 0
Share

For fun, you can Search for all the questions here about the Singleton design pattern. The thing is, there's two obvious ways to do it, which anyone would do if they never heard about design patterns or singletons. Also for fun, Search for "design patterns stupid."

avatar image rugved1991 · Apr 22, 2015 at 05:00 AM 0
Share

i am trying to implement command pattern. I know it will be used on my menu screen. but i am not sure how to implement it in Unity. I am able to implement design patterns in java.

avatar image AlwaysSunny · Apr 22, 2015 at 05:02 AM 0
Share

Please post non-answers as comments.

The phrase "command pattern" doesn't really communicate anything. Particularly for a menu screen, which makes your request even more confusing. I think you're trying to use jargon you picked up in some other development environment, and it does not translate to any other environment.

avatar image Owen-Reynolds · Apr 22, 2015 at 02:27 PM 1
Share

Sunny: Java-only corporate shops are big into "Design Patterns," and I think many Software engineering programs $$anonymous$$ch them as a Big Deal. "Tell me about something you implemented using Command Pattern" is a job interview question. There's a whole world where people think Command Pattern communicates something.

rugved: But, yeah, most working programmers think Design Patterns are useless jargon, and are annoyed when people ask about them. AFAI$$anonymous$$, Command Pattern is just a fancy word for csllbacks, which I believe the latest GUI system has.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mehtanitish · Sep 06, 2019 at 01:59 AM

Hi,

Unity is a Entity component engine, so it makes sense to assemble all your functionalities as Entity- component. On top of this Entity component pattern you can implement various patterns as per your requirement. Below are some of the design patterns for various use cases:

-For HUD design, victory condition or achievements system you can use Observer Pattern, the basic idea is that you should use the observer pattern when you need many objects to receive an update when another object changes, like for health change, coins collected, level completed, etc. There are various ways to implement Observer pattern like creating pure observer/subject class(not inheriting from monobehaviour) or once using monobehaviour. The one way I find most simple is to use scriptable objects as game events and then registering those to listener/observer. For more information on scriptable objects and using those as game events(for observer pattern) you can search for Unite Austin 2017 - Game Architecture with Scriptable Objects, in youtube. Really good stuff.

  • For resusing Scripts you can Use Type Object pattern, lets say you have a game where there are 4 type of dragons, each behaves different from another, so instead of creating 4 totally different classes, what you can do is create once single Dragon parent class implementing features common for all and for ones the features are not exactly same you can mark some methods virtual and use that parent Dragon class to inherit your Base classes which are each different dragons. I did the same in one of my game. Basically you use polymorphism here.

  • For reusing scene, that is having a single scene acting as different levels, you can use some Game Config file, here scriptable objects will be extremely helpful, you can store the information about each level in the game config file and use that file according to the level you want to play. Taking the dragons example, say at level 2 you want to have a different background, different sprite for dragon and so on, but basically the controller and image component for background are same, so using that config that you can use different image for dragon and background on the fly.

  • Command pattern when you need some functionality with replay or undo, you can use command pattern.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Owen-Reynolds · Sep 06, 2019 at 02:17 PM 0
Share

Sometimes old Q's get "pinged" and brought up -- check the date. It's fine to add a new answer to this 4-year-old old question, if that's what you were intending. If you want to discuss design patterns, the Forum area is better for back-and-forths and opinion.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Implementing game logic in a separate library: callbacks 1 Answer

Extending Behaviour instead of Monobehaviour 0 Answers

NullReferenceException while following Unity3d College tutorial @JasonWeimann 0 Answers

Weapon enchantments - designing the code architecture? 2 Answers

designing GameController UI relation 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges