Cabbage Logo
Back to Cabbage Site

SetChannel NullReference Error

Hi @giovannibedetti

Hope you are doing well!

I am having a little trouble with the SetChannel in Unity.

I was trying to set a frequency value from unity to the pitch channel in csound that was defined like the following:

In Csound:
kpitch chnget “pitch”
a1 expon .1, p3, 0.001

In Unity void Update():
csoundUnity.SetChannel(“pitch”, 200.0f);

However, as I try to run the game I am receiving the following error for this section from the CsoundUnity code, could you please let me know what could be the issue here?

Error Message:
NullReferenceException: Object reference not set to an instance of an object
CsoundUnity.SetChannel (System.String channel, System.Double val) (at Library/PackageCache/com.csound.csoundunity@470893372c/Runtime/CsoundUnity.cs:1002)
PitchShift.Update () (at Assets/Scripts/PitchShift.cs:54)

Error code ref

Thank you so much!


Hi Susan!
Quick answer: is csoundUnity correctly referenced in the inspector?

If you have:

public  CsoundUnity csound;

And then you call:

csound.SetChannel(channel, value);

You should ensure that csound is found in some way.
You could use:

csound = GetComponent<CsoundUnity>();

But this works if the CsoundUnity component is in the same game object of this script from where you’re calling it.

Or simply drag the CsoundUnity game object in the above “csound” public field.
Hope this will help!

Hi Giovanni,

Thank you so much, yea accidentally set it wrong at the inspector and didn’t realize that :sweat_smile:. I am hardcoding it in this time so it won’t be wrong.

I do also have another question, when I was trying to build a game with csoundUnity for WebGL, I had the following two types of error message “Library/PackageCache/com.csound.csoundunity@470893372c/Runtime/CsoundCsharp.cs(644,24): error CS0103: The name ‘_dllVersion’ does not exist in the current context”, “Library/PackageCache/com.csound.csoundunity@470893372c/Runtime/CsoundCsharp.cs(285,126): error CS0246: The type or namespace name ‘MYFLT’ could not be found (are you missing a using directive or an assembly reference?)”, do you know what could be the fix for this case?



Unfortunately we are not supporting the WebGL platform yet. That’s because Unity doesn’t support the OnAudioFilterRead callback on that platform, so we are unable to write the AudioSource content.
We will have to wait for Unity devs :wink:
Technically we could try using the Csound for web library, but still the implementation would be very different compared to other platforms and you wouldn’t be able to use it in the same way (so for example no AudioSource spatialization).
I could have a look after the 3.5.0 release, that hopefully will come before the winter.

I see, looking forward to it!