How to change audioclip in runtime?

the name of the clip

by user 262331051802755072

The clips array contains the paths

You dont need to concat anything

you can log console.log(this.clips) in awake to see

facepalm, checking

by user 262331051802755072

Should be like that at least

no no wait, in the id I get the name of the file, not the path

by user 262331051802755072

so I do have to concat

by user 262331051802755072

Where do you get it from?

And what does clips contain? is the path correct? Any errors?

clips array was the way to get the clips in the assets folder

by user 262331051802755072

image.png

by user 262331051802755072

I get the /assets/β€œid”.wav 404

by user 262331051802755072

with all but the one that was referenced by an audiosource to begin with

by user 262331051802755072

But the files exist at that path?

oh yeah, all of them are in the same path

by user 262331051802755072

Let me try to reproduce

This works for me as expected:

import { AudioSource, Behaviour, serializable } from "@needle-tools/engine";


export class ToggleAudio extends Behaviour {


    //@type UnityEngine.AudioClip[]
    @serializable()
    audio! : string[];

    @serializable(AudioSource)
    audioSource! : AudioSource;

    start(){
        let i = 0;
        setInterval(()=> {
            this.audioSource.play(this.audio[i++ % this.audio.length]);
        }, 2000)
    }
}

this too

 const clip = this.audio[i++ % this.audio.length];
console.log(clip);
this.audioSource.clip = clip;
this.audioSource.play();

ok the only diff I see is play(clip) instead of setclip then play

by user 262331051802755072