Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Windmere · Apr 01, 2019 at 05:40 AM · inventory systemscriptable objectabstract

Scriptable Object with Abstract Class field,Reference non-instanced inherited class through abstract field.

I built my inventory system based off scriptable objects with a base item class. The weapon scriptable object has a field that’s type of WeaponFunction, an abstract class with an abstract Attack() method in it.

I made a Sword class that inherits WeaponFunction and overrides the Attack() method. The Unity Editor won’t accept the Sword class as a valid entry in the scriptable object’s WeaponFunction field.

Is there a better way to do this? Is there an example of this kind of architecture somewhere I can take a look and see how someone else did it better? ,I built my inventory system around a bunch of different types of an item scriptable object. For the weapon item I defined an abstract class for that contains an abstract Attack() method and have a variable in the scriptable object that’s type of the abstract class.

When I write a new class, Sword, that inherits the WeaponFunctions abstract class unity won’t let me assign it to the WeaponFunctions class.

Is there a better way to do what I’m doing? How has this been done before? Is there a small fix I can do to get my system to work?

Comment
Add comment · Show 2
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 RobAnthem · Apr 01, 2019 at 06:19 AM 0
Share

What you'll want to do is create an ID for the WeaponFunctions, and load them either dynamically or into a dictionary, and then have a ID reference in the item so that it acquires the proper reference. You see, Unity doesn't handle serialization of inheritance on members and fields, so to get around it, you need to assign it at runtime, or keep the reference elsewhere.

avatar image xxmariofer · Apr 01, 2019 at 07:36 AM 0
Share

there is something wrong in the way you are oding it since, scriptable objects are just claasses and can be use as parent/child without problems, share your code and i will try to find the error

0 Replies

· Add your reply
  • Sort: 

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

103 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 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

Problems calling functions from Scriptable Objects 0 Answers

List keeps emptying itself 0 Answers

Need opinions on handling Scriptable Objects 1 Answer

How to Instantiate objects that are Scriptable Objects 0 Answers

How to Store and Reference Skills Flexibly? 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