How to save audio clips?
-
- Posts: 23
- Joined: Sat Sep 05, 2020 12:53 pm
How to save audio clips?
I have an audio source that has it's clip change over time.
When I save the clip it produces giant save file... can't I just save the reference of the clip?
When I save the clip it produces giant save file... can't I just save the reference of the clip?
Re: How to save audio clips?
Hi there,
If you save the clip directly using ES3.Save or ES3.SaveAudio then it will be saved by value and reference. However, if you save the clip as a field of another class using ES3.Save (e.g. by saving your AudioSource) then it will be saved by reference (assuming a reference to the AudioClip exists in your scene).
Alternatively you can create an ES3Settings object which specifies a referenceMode of ES3.ReferenceMode.ByRef and provide this as a parameter to the ES3.Save method when saving.
All the best,
Joel
If you save the clip directly using ES3.Save or ES3.SaveAudio then it will be saved by value and reference. However, if you save the clip as a field of another class using ES3.Save (e.g. by saving your AudioSource) then it will be saved by reference (assuming a reference to the AudioClip exists in your scene).
Alternatively you can create an ES3Settings object which specifies a referenceMode of ES3.ReferenceMode.ByRef and provide this as a parameter to the ES3.Save method when saving.
All the best,
Joel
-
- Posts: 23
- Joined: Sat Sep 05, 2020 12:53 pm
Re: How to save audio clips?
Hi there, thanks for answering. Unfortunately both of the solutions you proposed don't work.
For the first solution I saved the audiosource
and loaded with
It retrieves the audiosource's ref but it doesn't change it's clip to what it was at the moment of saving, in fact, it doesnt change its values at all.
So I tried to save the clip by reference
But it still generate a huge file, here's how it look like
which is too bad because by the look of it, it retrieves the reference which is "_ES3Ref" : "1843017990479932329". But it also adds everything about the clip like the name and all the sample data which we shouldn't need because we have the ref anyway.
For the first solution I saved the audiosource
Code: Select all
ES3.Save("audioSource", audioSource, saveSO.saveName)
Code: Select all
audioSource = ES3.Load("audioSource", saveSO.saveName, audioSource)
So I tried to save the clip by reference
Code: Select all
ES3Settings settings = new ES3Settings();
settings.referenceMode = ES3.ReferenceMode.ByRef;
ES3.Save("audioSourceClip", audioSource.clip, saveSO.saveName, settings);
Code: Select all
"audioSourceClip" : {
"__type" : "UnityEngine.AudioClip,UnityEngine.AudioModule",
"value" : {
"_ES3Ref" : "1843017990479932329",
"name" : "acid burn",
"samples" : 63360,
"channels" : 2,
"frequency" : 44100,
"sampleData" : [
**a huge array of numbers**
]
}
}
Re: How to save audio clips?
Hi there,
Apologies, I didn’t realise that Unity didn’t make the AudioSource class serializable at runtime. In this case you would need to go to Tools > Easy Save 3 > Types, search for AudioSource and select the ‘clip’ property.
All the best,
Joel
Apologies, I didn’t realise that Unity didn’t make the AudioSource class serializable at runtime. In this case you would need to go to Tools > Easy Save 3 > Types, search for AudioSource and select the ‘clip’ property.
All the best,
Joel
-
- Posts: 23
- Joined: Sat Sep 05, 2020 12:53 pm
Re: How to save audio clips?
Thanks! that did the trick
-
- Posts: 23
- Joined: Sat Sep 05, 2020 12:53 pm
Re: How to save audio clips?
I've got another problem, the "_ES3Ref" of a clip changes everytime I log out and re enter the game, same for the music scriptable object. This means that everything seem to work fine during a session of gameplay but If I quit the game then re enter the game and I load, the music will not play because the _ES3Ref is no longer valid.
Right clicking on the scriptable object and clicking "Add Reference to manager" did not solve the issue
Right clicking on the scriptable object and clicking "Add Reference to manager" did not solve the issue
Re: How to save audio clips?
Hi there,
This usually means that your AudioClip is created or modified at runtime (which creates a new instance of the AudioClip), meaning that would be impossible to save it by reference between sessions.
If you don't feel this is the case for you, please could you create a new project with a very simple scene which replicates this and private message it to me with instructions.
All the best,
Joel
This usually means that your AudioClip is created or modified at runtime (which creates a new instance of the AudioClip), meaning that would be impossible to save it by reference between sessions.
If you don't feel this is the case for you, please could you create a new project with a very simple scene which replicates this and private message it to me with instructions.
All the best,
Joel
-
- Posts: 23
- Joined: Sat Sep 05, 2020 12:53 pm
Re: How to save audio clips?
no no I don't create or modify clips or scriptable objects during runtime, is there a way to know if somthing's on the ES3 reference mgr list without having to open the whole reference list that cause the editor to freeze?
-
- Posts: 23
- Joined: Sat Sep 05, 2020 12:53 pm
Re: How to save audio clips?
Also adding multiple references at once to the manager doesnt seem to work. I select a bunch of files and right click -> Add reference to manager, and only the first one is added
Re: How to save audio clips?
Hi there,
You can use ES3ReferenceMgr.Current.Get(Object obj) to determine whether something is in the reference manager.
All the best,
Joel
You can use ES3ReferenceMgr.Current.Get(Object obj) to determine whether something is in the reference manager.
This appears to be working fine for me, and I've had no other reports of this. Are you on the latest version of Easy Save?Also adding multiple references at once to the manager doesnt seem to work. I select a bunch of files and right click -> Add reference to manager, and only the first one is added
All the best,
Joel