@SeventhString I’ve been doing that for a decade. This post is two years old. The bug was opened and closed back in 2021, the ticket # is 1322096. Nothing has been fixed as far as I know. Correct me if I’m wrong.
Hi sir! I could not find the ticket you mention :
If you have a link to the issue tracker or any other reference, I’d be happy to dig and try to find what happened with that.
I’m having this issue as well. I’m unable to save instances of audioclips
I’m doing this: (_target.clipSamples is a float array of samples from an existing audioclip)
Sorry I haven’t yet, I did setup a repro project and made it happen but didn’t debug it yet. I’ll bring that back near the top of the pile for this week.
Alright here it is! My understanding of this problem is that it is more about the realm of influence of these functions than a bug in Unity.
The purpose of AudioClip.Create is to create on the fly a runtime object wrapping audio data. Interestingly enough, the AudioClip object itself does not own the audio data, only references it. This means it can only be bound to runtime generated or pre-serialized memory.
On the other side, AssetDatabase.CreateAsset(audioClip, targetPath) only creates/serializes the AudioClip, NOT the associated audio data. Also asset creation only occurs in the context of edition, and I believe it’s not even taking place during the Editor Play Mode.
So these two do not really fit in the same workflow. If your goal is to create new assets, you would have to write a file to disk and then import it with AssetDatabase to add it to the project. If the point is to create files on the fly at runtime, it would still be about writing a file to disk but then loading it with a WebRequest.
We could certainly argue that it’s not how it should happen and submit a bug report to the Assets team, but as there is a kind of workaround, I doubt they would engage with this soon.
Hey, thanks for having a look at the issue.
I feel like I have an understanding of the issue now, although I think it’s a bit strange that the audioclip is not containing the clip data itself. There’s probably a good reason for it I guess.
For now my workaround has been to just store the clip data in an array in a scriptable object. That works, but I can’t preview it, and all that stuff. Actually creating a file on disk and loading it, would be a better option. I’ll try it.