OSC in C++

In my project I receive a huge OSC message. I’m using the OSC plugin and BluePrints to process it. On lower end machines I’m having performance issues, so I’d like to processe the OSC message in a C++ function.

My question is: how do I pass the OSCMessage object to the C++ function?

Anyone can please help?

An implementation in c++ as a lib

Header

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "OSCFunctionLibrary.generated.h"

/**
 * 
 */
UCLASS()
class YOUR_API UOSCFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

		UFUNCTION(BlueprintCallable)
		static void ProcessOSCMessage(UPARAM(ref) FOSCMessage &passedMessage);

};

cpp

#include "OSCFunctionLibrary.h"
#include "OSCMessage.h" 


void UOSCFunctionLibrary::ProcessOSCMessage(FOSCMessage &passedMessage) {
	FOSCAddress address = passedMessage.GetAddress();
	const TSharedPtr<IOSCPacket> packet =  passedMessage.GetPacket();

	FOSCAddress newAdress;	
	passedMessage.SetAddress(newAdress);
	

	FString IPAddress = "192.168.3.3";
	int32 Port = 33;
	const uint8* InPacketType = 0;
	TSharedPtr<IOSCPacket> packet2 = IOSCPacket::CreatePacket(InPacketType, IPAddress, Port);
	
	passedMessage.SetPacket(packet2);

	
}

add “OSC” to the modules in your build file

OFC ProcessOSCMessage should have a return value or a passed in ref output. (right now the mssage is processed “in place”)

You could also offload the processing to another core through FRunnable seeing as the data doesn’t directly interact with the game world during processing.

Wow.
Thank you @3dRaven!
Many times I fire away questions on this forum doubting anything useful will get back, but your answer is gold, thank you!
I’ll try that ASAP and I’ll let you know about it.
Ciao!

1 Like