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 Polantaris · Jan 02, 2014 at 12:59 AM · prefabinspectorpolymorphism

Assigning child script to parent field in Inspector

In my project, I have gone about creating character Abilities (skills, essentially) by creating a base Class, Ability, that will be inherited by all Abilities created. It's an abstract class with some undefined methods that will change based on the Ability that the child will be, as well as some properties whose values will change based on the Ability as well.

Overall it is working, but now I've gotten to the point where I need to be able to dynamically add and remove them mid-game from the Player object (and eventually NPCs, monsters, etc.), however I'm running into some issues.

On my Player script, I've given it a size 10 Array of Abilities called skills - By my game's ruleset, the Player can only have 10 Abilities active at any time, so the skills array is specifically the skills that are actively set for the Player's use at that moment. The problem is that for testing, and eventually non-dynamic setting of these (IE, a monster may only have 1 Ability ever, regardless of the point in the game, so I'd mind as well set that into its prefab), I've attempted to add a script that defines a for-testing Ability named BasicAttack. I cannot add this script directly to the array in the Inspector. I imagine it's because it's a Script, and technically not an Ability flat out.

Here's my question: Do I need to make a prefab for every Ability, and simply give it the script of that Ability, then give that AbilityPrefab to the Inspetor, or what? That doesn't exactly seem correct to me because a prefab is a GameObject, not an Ability (or whatever I want it to be). How exactly should I be handling this?

I've also seen a couple of questions that mention that you cannot place a child class directly into the Inspector - It doesn't care about Inheritance or Polymorphism at all. If this is the case, how do I go about handling this issue? I was reading something about making a Custom Inspector object that represents the base class, but all the information I can find about this is vague and the documentation has no C# reference, only UnityScript, which doesn't really help me because the syntax is significantly different from what I can tell.

Any information in regards to this problem would be greatly appreciated, thanks in advance.

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 Polantaris · Jan 02, 2014 at 03:14 AM

I found the answer:

http://wiki.unity3d.com/index.php?title=CreateScriptableObjectAsset

This page showed me how to create a ScriptableObject Asset, which I can then place into my Array directly through the Inspector when necessary. It doesn't seem like the older polymorphism questions I saw when searching for a solution apply anymore, I was able to place my BasicAttack testing Ability into an Ability field and had no problems.

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

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

18 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

Related Questions

How to set a default prefab on a C# script? 1 Answer

prefab contents of the Custom inspector disappear. 0 Answers

Prefab not inheriting GameObject when instantiated 1 Answer

Linking prefabs 0 Answers

What is the name of/How do I use the box in the Script Inspector that allows you to assign values to Public data? 2 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