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 planC · Jan 04, 2011 at 09:51 AM · serializationclasscustom

custom class serialization problem

I made a class like this

[System.Serializable]
public class AudioClipPlayer : Object
{
    private AudioClip clip;
    private float repeat;
};

and on the Inspector, it appears like this

-----------------------------------------------------
Audio Clip Player          None (Audio Clip Player) @
-----------------------------------------------------

Here's the problem I want to drag and drop a audio file to the 'None' area. But I have no idea what I have to do. I want to look like this

----------------------------------------------
Audio Clip Player          None (Audio Clip) @
----------------------------------------------

And I want to look exactly like above.. because I wanna make a array for AudioClipPlayer like this

[System.Serializable]
public class ZombiAudioClips
{
    public AudioClipPlayer[] idleClips;
}

I want to make that Unity recognize AudioClipPlayer to AudioClip. Is that possible? Thx for reading.

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 Mike 3 · Jan 04, 2011 at 09:57 AM

Remove the : Object for a start, it'll be making your class inherit UnityEngine.Object which makes very little sense. After that, you'll want to either make the fields public, or add [SerializeField] above both of them

[System.Serializable] public class AudioClipPlayer {

 public AudioClip clip;
 public float repeat;

};

or

[System.Serializable]
public class AudioClipPlayer
{
    [SerializeField]
    private AudioClip clip;
    [SerializeField]
    private float repeat; //note, these aren't going to be accessible from outside the class
};
Comment
Add comment · Show 10 · 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 planC · Jan 04, 2011 at 10:10 AM 0
Share

thank you $$anonymous$$ike. but I want exactly looking like above.. because I wanna make a array for AudioClipPlayer like this [System.Serializable] public class ZombiAudioClips { public AudioClipPlayer[] idleClips; }

avatar image Mike 3 · Jan 04, 2011 at 10:19 AM 0
Share

Then it can't work. If you change it to how i'm saying, it should work as you want it. I'll add in a fixed class as an example

avatar image Mike 3 · Jan 04, 2011 at 10:22 AM 0
Share

I would go with the top example, the bottom one is probably going to have protection issues trying to access the private members

avatar image planC · Jan 04, 2011 at 10:43 AM 0
Share

It does not work for the code 'AudioClipPlayer[] idleClips'. I want to add some audio files to idleClips.

avatar image Mike 3 · Jan 04, 2011 at 11:01 AM 0
Share

Which one are you trying?

Show more comments

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

No one has followed this question yet.

Related Questions

Custom Class Array Serialization Problem 0 Answers

Why is my C# array of objects fully populated when some of them should be null? 3 Answers

Property drawer stops variables from being read 0 Answers

Best practice custom class with GameObject 0 Answers

Custom Documentation for Monodevelop 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