Synching channels using Bass.Net for Windows with Unity

I’ve done a few searches on the forum and noticed that a few people have been successfully using Bass with Unity, so I thought I’d try my luck and see if anyone could help me out as I’m all out of ideas at this point.

I’m attempting to use the channel synching features of Bass.Net to playback samples in time with one another. I’ve successfully written a C# .Net 2.0 Console application that carries out this behaviour perfectly using Bass.Net and I thought it would be a relatively trivial task to port it over to Unity.

It seems I was wrong!

Here’s my method:

  1. Create a Bass Mixer Stream as the main timeline
  2. Add the audio streams to the mixer as channels in a paused state
  3. Setup the SYNCPROC to callback when the main timeline reaches a certain point.
  4. In the SYNCPROC function reset the position of main timeline to the start, so as to call the SYNCPROC function again at the set point in the main timeline

By carrying out some Console debugging it seems that it’s some point after 4 that my problems seem to arise.

The Unity Editor crashes abruptly with no warning whatsoever. There is nothing in the Editor.log’s out of the ordinary, apart from once I did find this quite vague exception at the end of a relevant Editor.log:

If anyone has had any experience with Bass and Unity or any advice using plugins in general, I’d love to hear from you.

Thanks,

Luke

The error is simply that the Bass event is occuring on its own thread different to Unity’s main thread.

CompareBaseObjectsInternal can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don’t use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.

I have only just discovered this problem so trying to fix. If i get a solution will post it here. Anyone else finds the solution please post before me !
P.S. Wondering if spawning another thread and performing the BASS logic would stop this. Unsure at moment will test.