Cabbage Logo
Back to Cabbage Site

VR CsoundUnity Sequencer

Hi Rory,

I’m trying to build a interactable sequencer in Unity following your simple sequencer tutorial, and I am using the Auto Hand VR package to build it in the setting that if you throw the bouncy ball and it collides with the cube, one cube will be triggered.

I was able to have it working in non-VR mode, but after I imported in VR, the sequencer instrument doesn’t seem to trigger, do you know what could be the potential issue?

Hi @Xiaomeng_Zhong,

The Sequencer works using the “OnMouseDown” callback, and that won’t work on VR.
You will have to implement your own interaction. Something like:

void OnCollisionEnter()
{
    sequencer.UpdateSequencerPad(Int32.Parse(gameObject.name));
}
1 Like

Hi @giovannibedetti,

Thank you for the response! My VR sequencer is set to trigger on collision, in the non-vr version, when the instrument starts playing, the cubes has a resize function to indicate that the sequencer is actually running, however that is not the same case in the VR version, they just stay stable and doesn’t trigger.

Are there any errors in the console? Is CsoundUnity initializing?
I believe the sequencer is loading a sound sample, is it loaded?

Do you have the project uploaded somewhere so that I can have a look? Maybe on github?
Or otherwise upload a zip somewhere and send me the link via pm if you don’t want to make it public.
I’m super busy until next week so not sure when I will be able to help, though.

Hi @giovannibedetti

There are no errors in the console other than the “you have more than one audio listeners”, if I remembered correctly. I can’t really run it right now because I’m travelling and don’t have my headset with me sadly.

https://drive.google.com/file/d/1lMklgCeGNfeSxgDfG9eeMiAHrgpxArCX/view?usp=share_link

The one I’m using is not loading the sound sample, it’s using the pluck opcode. I am attaching the project here and please let me know if you can access it!

Sorry for the slow responding.

I had a look. Unfortunately a couple of scripts are missing (I guess some packages are referenced directly in your hard disk), so I cannot test it properly.
Can you fix this? or maybe send me the two scripts that are missing:
image
image
(Btw you should use “Device” mode in the XR Head Tracking so that the mode can be selected in the VR Headset instead of having it “hardcoded” inside the app, since the user could want to sit - like me :sweat_smile:)
Also I noticed you are using several copies of the same script (PitchShift1.cs) only to update a different channel in Csound. It should be enough to do this:

// Set the csound channel with the mapped value
csoundUnity.SetChannel(channelName, mappedValue);

then you have to change the value in the inspector, like you’re already doing:
image

Thank you for the heads up! I have fixed the channel name and the device mode.

This is what the missing script sections looks like on my end, I think it’s because of the AutoHand controller that I am using… I’m not really sure what I should do here…

When I tried to open your project Unity couldn’t identify the editor version. So I went with 2021LTS. Which version are you using? Also when sharing the project you can leave out the Library folder, which will be rebuilt.

Thank you for the heads up! The version I was using was 2021.3.19f1 for Unity, and for CsoundUnity I believe I used version 3.3.1 that was sent to me by Dr. B, because for some reason I couldn’t get CsoundUnity 3.4.0 to work on any of my machines.

Feel free to report if you have any issue importing the package. This can help others too!
Btw you can download every version from the releases page, it should work also if not importing through the Package Manager. You can place the unzipped folder anywhere in your project.
I will try again your project, trying to fix the missing scripts.

Ok after removing the Examples folder from the Auto Hand package the project compiles correctly. Not sure how it can work on your side, but that’s ok :sweat_smile:
So basically you just need to trigger something when touching the spheres? Using that package it should be easy using the OnGrab/OnRelease event.
Basically you could do something like this:

to start instrument 1 indefinitely, and OnRelease you could stop it using

i-1 0 -1

Of course this is not enough if you want to define which instrument to call depending on which object you grab. In that case you will need to subscribe to the event using a script.
I cannot do it right now (it’s very late here) but I will try to have a closer look tomorrow evening.

Ok I was able to make it work.
Everything was pretty much ok except for the handling of collisions.
Since you have set IsTrigger on the SphereCollider of your BounceyBall:

image

you need to use OnTriggerEnter to detect triggers :wink:
I have changed your script with this and it works on the editor dragging the sphere with the mouse in the scene (I haven’t tried on the Quest yet)

    private void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.CompareTag("ball"))
        {
            Debug.Log($"CubeController: {this.name} TRIGGER with BALL {other.gameObject.name}");
            if (rend.material.color == offMaterial.color)
            {
                rend.material = onMaterial;
                camera.GetComponent<MainController>().EnableCubeToPlaySound(cubeIndex);
            }
            else
            {
                rend.material = offMaterial;
                camera.GetComponent<MainController>().EnableCubeToPlaySound(cubeIndex);
            }
        }
    }

Some other notes:
I created a prefab for the cubes, and a single PitchShift script that I use on all of them, just reassigning the Spheres and changing the channelName.
I commented out the OnCollisionEnter section inside the BouncyBallHit script, since it’s superfluous, you’re handling the trigger in the CubeController already, and it was calling the same method:

mainController.EnableCubeToPlaySound(index)

that is called above OnTriggerEnter.

Here is a unity package with the scene and its dependencies:
VR_Sequencer.unitypackage (62.4 KB)
except the Auto Hand scripts, and all the rest that you should already have. As a matter of fact I think you shouldn’t share a project that uses a paid plugin, maybe we should remove that link you posted above :sweat_smile:
Let me know if it imports correctly and if it works as expected!

Thank you so much for the update! Unfortunately I don’t have my headset until early June so I can’t test it right away. I have removed the link above. One of the main issue I had was that when I build the project in VR, the sequencer wouldn’t run, the cube wouldn’t resize but that doesn’t seems to be the case when I shared the project with a friend of mine.

I will try this once I am back home with my headsets, thank you so much for the help!

If the sequencer doesn’t update it could be that the Csound dll is not loaded. Be sure to build with IL2CPP enabled and export a 64bits app!
Let us know how it goes :wink:
Also to help debugging have a look at the AndroidLogcat package, it will offer logging from the Oculus device directly in the Unity editor, just keep the cable connected to your PC/Mac