- Home /
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.
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
};
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; }
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
I would go with the top example, the bottom one is probably going to have protection issues trying to access the private members
It does not work for the code 'AudioClipPlayer[] idleClips'. I want to add some audio files to idleClips.
Your answer
![](https://koobas.hobune.stream/wayback/20220613093952im_/https://answers.unity.com/themes/thub/images/avi.jpg)