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 /
avatar image
0
Question by lilGrim · Oct 21, 2013 at 07:02 PM · scriptableobjectinheritancemonobehaviourgeneric list

Adding inherited class to list

Hi I have 4 classes that work together as follows

BSpell (contains all functions for generic spells

SpellProperties : BSpell (each spell will have its own such as "fireballProperties, this contains all the detail information such as damage ect)

SpellMechanics : SpellProperties (contains mechanics of spell, used on a gameobject prefab)

PlayerClass

This is where my problem comes in, in PlayerClass i have a public List spellBook. i would like to add the different SpellProperties to this list (through code), but if BSpell inherits from mono then a new instance cannot be instantiated. if BSpell inherits from ScriptableObject then SpellMechanics cannot affect its gameobject.

Any help would be appreciated

Comment
Add comment
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

1 Reply

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

Answer by mattmanj17 · Oct 21, 2013 at 07:33 PM

Your notation is a little vague. You say each spell "has a" spellProperties object which keeps track of information such as damage, etc, but the notation "SpellProperties:BSpell" indicates spellProperties inherits from BSpell.(if this distinction dose not make sense, look into "has a" vs "is a")

I will answer your question for each case:

Lets say your character has three scripts attached to him, say FireBall, MagicMissil, and ConeOfCold.

If each of these spells "is a" SpellProperties (if they inherit from it), then just use

 spellbook.add(gameobject.getcomponent<fireball>());

If each of these spells "has a" SpellProperties (if each one has a spell properties as an element to keep track of various stats), then use this

 spellbook.add(gameobject.getcomponent<fireball>().fireballProperties);

For each other "spell" you would just use its name instead of "fireball".

if you want to add a new spell to the player, just use addcomponent().

Comment
Add comment · Show 2 · 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 lilGrim · Oct 21, 2013 at 10:05 PM 0
Share

Tnx for the answer, my Bspell has all the fields but for instance I make FireballProperties that inherits from BSpell and all fireball details are then assigned such as name, dmg etc, FireballProperties is not added onto a game object, I would like to add the FireballProperties to the list. But I cannot instatiate "new" because of monobehaviour. Fireball$$anonymous$$echanics inherits from FireballProperties and is attached to a prefab and contains the spell's movement and so on.

What I'm doing now is splitting properties and mechanics so that mechanics is monobehaviour and properties is scriptableobject and then just referencing properties from mechanics

avatar image mattmanj17 · Oct 21, 2013 at 11:53 PM 0
Share

glad you fixed your problem. if you figured it out, could you close the question or mark the answer as correct, so the question dosn't stay up.

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

15 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

Related Questions

Why child ScriptableObjects class instance cannot be placed in their parent ScriptableObject field in the inspector? 1 Answer

C# Conception - Hide inherited members and functions 1 Answer

Are there any reasons why I should use ScriptableObject instead of MonoBehaviour (or vice-versa)? 3 Answers

ScriptableObject and Monobehaviour 1 Answer

How to make a List that can store anything that implements an interface? 4 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