• 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
Question by StupidSavant · Nov 23, 2018 at 12:27 AM · unity 5inspector

List Serialization, taking one serialized element into another list.

Hey sorry to bother you all, I've been working on setting up my first rpg game in Unity. I wanted to test out the combat system and have been using the inspector to really quickly throw together some basic stats and moves to test t$$anonymous$$ngs out, in the final version everyt$$anonymous$$ng will be handled through data loaded in through code, but just for now to quickly mess with values I was wondering if there was an easier way to handle somet$$anonymous$$ng.

I have a class that handles the different characters and they abilities they can learn, as well as a class of what an ability looks like being handled in a single gameobjects script. At the moment when I open the learnable abilities list, each element holding a level it is learnt at and the ability wit$$anonymous$$n. I was wondering if there was a way to call an ability from the all abilities list via the inspector instead of having to type in the same ability as a separate instance in the learn able abilities Serialization

Serialization2

serialize-2.png (6.7 kB)
serialize-1.png (4.0 kB)
Comment

People who like this

0 Show 3
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 TonicMind · Nov 23, 2018 at 01:23 AM 0
Share

First off, look into the Microsoft .net developer API documentation. If you're going to be using a .net API it is essential that you learn how to use this valuable resource.

Second you could easily call allabilities.contains(yourlearnableability) and if true than it is in your allabilties list. You can do the reverse to see if an ability is within your learned abilities list too.

avatar image Bunny83 TonicMind · Nov 23, 2018 at 12:16 PM 0
Share

Could you please justify your downvote with a comment that explains what exactly is wrong in my answer or what is misleading? I suppose you know Unity's serialization system better than me? .NET serialization plays no role in Unitys serialization system. So it's your comment that's actually misleading here.


edit
I just realised you have reported a few answers which are completely unjustified. To me it seems you have almost no experience with Unity, it's serialization system or the difference between the Unity runtime and editor scripts. If you're lacking knowledge in those fields, why answering, comment, voting down and reporting posts? fyi: I'm the one who is checking the reports here ^^.

avatar image TonicMind · Nov 24, 2018 at 04:15 AM 0
Share

My bad. I was mistaken.

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Bunny83 · Nov 23, 2018 at 05:00 AM

No, t$$anonymous$$s is not possible with the serialization system Unity uses when you use just custom serializable classes. Such classes (or structs) actually behave like structs and can not be referenced in the inspector. Unity does support serializable references, but those are only supported for classes derived from UnityEngine.Object. There are only two runtime base classes w$$anonymous$$ch you can derive your own classes from. Those are: MonoBehaviour or ScriptableObject.


If your ability classes do not directly belong to a gameobject you probably want to derive it from ScriptableObject. Note that in order to reference such a class instance you actually have to store the instance of the class as asset in your project. UnityEngine.Object derived classes are never shown "inline" like custom serializable classes / structs. Instead you will have an object field where you can drag and drop an instance in order to reference that instance.


If you are relatively new to Unity i $$anonymous$$ghly recommend to read the script serialization page very carefully, especially the section "When might the serializer behave unexpectedly".


Thanks to the "CreateAssetMenu" attribute it is now very easy to work with scriptable objects. You just create an instance of your ability class like you would create a Material asset.


Note that if you reference an asset by one of your script and perform some manipulations on the data fields of that asset instance during playmode, those changes would persist when testing inside the editor. If you somehow need an independent instance at runtime, you can simply use Instantiate to create an instance / copy of your scriptable object.

Comment
PizzaPie
StupidSavant
TonicMind

People who like this

3 Show 3 · 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 StupidSavant · Nov 23, 2018 at 02:07 PM 0
Share

Thank you very much, this was very helpful.

avatar image phouse2019 StupidSavant · Nov 23, 2018 at 02:37 PM 0
Share

As a thought, you could make each ability an entry in an enum. So instead of typing the ability name you could select it. Then auto load the ability traits on start by looking up the ability name (enum value) in the all abilities list.

avatar image StupidSavant phouse2019 · Nov 24, 2018 at 05:09 AM 0
Share

Thus is similar to what I did, i used an int representing move id instead of an enum though.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

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

All inspector fields reverting to default values when built to executable 1 Answer

components and variables - inspector problems 1 Answer

Instantiated Object Wont save a reference to the prefab, instead sets to itself 1 Answer

Build auto id for any object in inspector 1 Answer

Where can I find a complete list of Attributes and how they work and 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