Need help with modding and API

#1
Hello, I'm dimmon3991, author of this mod: https://steamcommunity.com/sharedfiles/filedetails/?id=1526148940

I got some issues with adding sound to my block. Of course i did steps:

1. Put audio file with .ogg extension to Resource folder
2. Declare audio in Mod.xml

I learn how to make custom script from "Drum pad and War horn" tutorials and API's. Result - my mod in workshop.

But i don't get how to declare and use sound in script.

In Unity 3D it's no problem to me, but not in "besiege modding" case.

If someone have code from standard besiege blocks or other examples, please gimme that))

Or just tell me, please, how use modding API, it's not clear to me without code examples
 

spaar

Active Member
#2
The basic idea is something like this:

C#:
// If you want to use the sound in a block:

public class YourBlockScript : BlockScript {
    private static ModAudioClip audioClip;
    public AudioSource source;
    
    public override void OnPrefabCreation() {
        audioClip = ModResource.GetAudioClip("the-name-you-declared-in-the-manifest");
        
        // If you want the sound to originate from your block in the 3D world, you need
        // an audio source attached.
        source = gameObject.AddComponent<AudioSource>();
    }
    
    // Then you can use it like this for example:
    public override void SimulateUpdateAlways() {
        if (<something>) {
            source.clip = audioClip;
            source.Play();
        }
    }
}
This should work in the usual case, unless the sound file is very large.

Apart from that, if you have further questions I recommend joining the Official Besiege Discord server. There are more active modders there than there that are generally happy to help.
 
#3
[QUOTE="spaar[/QUOTE]

OH MY GOD, THANKS!

I was so close... I use "Resource.GetAudioClip" instead "ModResource.GetAudioClip" o_O

Again, thanks for answer))
I'll check Discord server))
 
Top