Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
avatar image
0
Question by Darkhalo45 · Feb 25, 2018 at 10:58 PM · databaseinheritancemonobehaviour

How to make different types of Objects in database?

How should I make a database of different types of buildings, where each one of them does different things(has different variables and functions). I am thinking of Inheritance, but not too sure how I should implement it. The main problem is with MonoBehaviour. Some of these buildings will need the Update() function, for example, to generate money every second. How do I store monobehaviour scripts to a scriptableobject database then?

Comment
Add comment · Show 1
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 Commoble · Feb 25, 2018 at 11:26 PM 0
Share

You can inherit from $$anonymous$$onoBehaviour without breaking Update() or other message functions. Just put Update() in your parent class, and have it call some other function, e.g. doUpdate(), then override doUpdate() in your child classes

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Xarbrough · Feb 25, 2018 at 11:28 PM

Why do you need a database? Or why do you think you need to store MonoBehaviour scripts in a ScriptableObject? ScriptableObjects are not databases, btw, although I know you are probably just using this term loosely. ScriptableObjects are very similar to MonoBehaviours, but they can be serialized (e..g save to the project folder as an asset) without having to be attached to a GameObject in a scene. On the C++ side of the engine, both classes are in fact treated the same way.

If you need Update, you will need a MonoBehaviour in the scene, so a building prefab is a good idea. However, you can decide which data to store with the prefab and which data to store in additional ScriptableObjets.

If you use inheritance, Update is still no problem because you can make the base class Update a virtual method and override in child classes (and call base.Update() if you also want the base class behaviour).

Generally, I would favour composition over inheritance. I've implemented a strategy game with buildings, where the building class was only a very thin wrapper that contained a tile position. Then we had components like "ResourceProducer", which was basically a timer which would increase the count of ScriptableObject data containers like "ItemInventory".

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 Darkhalo45 · Feb 26, 2018 at 02:06 PM 0
Share

Thank you for the answer, I got the idea, but I have a ScriptableObject with a list inside it, which is basically a database of different type of buildings that I have. I figured it out now tho.

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

81 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Working with Items and Class Inheritance for an RPG Item Database 1 Answer

Is it possible to create game object/prefab from file? 2 Answers

MonoBehaviour inheritance problem 1 Answer

What is the signature of Awake() and Start() 1 Answer

C# Conception - Hide inherited members and functions 1 Answer


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