Getting MIDI Messages as Unity Plugin

Hi all! I’m curious if anyone has had any luck getting MIDI messages to their Audio Processor while running it as a Unity Wrapper plug-in. I’m trying to avoid having Unity send the MIDI messages (using Minis package) because of the latency, and it doesn’t intuitively make sense for Unity to do so.

My thought is that, when I hit a key on my MIDI keyboard, that input should be captured by a JUCE Audio Device Manager, and callbacks should send that message to a MIDI Collector and eventually processed by the MIDI buffer in the processBlock, like so:

void AudioProcessorUnityWrapper::create(UnityAudioEffectState* state)

{

deviceManager.initialiseWithDefaultDevices(0, 2); 
midiCollector.reset(state->sampleRate);

auto midiInputs = juce::MidiInput::getAvailableDevices();
for (auto& input : midiInputs) {
    deviceManager.setMidiInputEnabled(input.identifier, true);
}

deviceManager.addMidiInputDeviceCallback({}, &midiCollector);

}

void AudioProcessorUnityWrapper::processBuffers(…)

{

MidiBuffer mb;

midiCollector.removeNextBlockOfMessages(mb, bufferSize);

pluginInstance→processBlock(scratchBuffer, mb);

}

juce::AudioDeviceManager deviceManager;

juce::MidiMessageCollector midiCollector;

This all initializes fine and well, but no callbacks are called when I start pressing keys on the MIDI keyboard, the midiCollector never fills up with any messages, and AudioDeviceManager::handleIncomingMidiMessageIntis never called.

So at this point I’m wondering, is this even possible? It would make sense that Unity can only send MIDI messages, which is fine, but I hope there is a less latent solution.

Thank you!