-
Notifications
You must be signed in to change notification settings - Fork 8
Getting Started
- At least one Nintendo Switch Joy Con
- A Bluetooth adapter compatible with Joy Con
- Unreal Engine 4.25.x (It is possible that it works in previous versions)
- When connecting a Joy Con in the editor it will remain connected even after the simulation/play is over and will stop working when playing again, the only solution is to resume de connection with ResumeConnection node.
Clone the repository and you're ready to go to the next step.
- Clone the repository
- Convert your project to C++ (If it is only a blueprint)
- Copy the
Plugins
folder inside the repository to your project's root folder - Right click on your project's
<name>.uproject
and select "Generate Visual Studio project files" - Open the project in Visual Studio (Recommended) or your preferred IDE
- Compile your project, if all goes well you are ready to proceed 😸
Now it's time to pair the joy cons with the operating system. If you experience difficulty you can follow the tutorial below.
How to connect a Nintendo Switch controller to your PC
After pairing you will need to create code for the controls to connect to the plugin.
You can use the following examples:
Code for Ctrl + C and Ctrl + V
Code for Ctrl + C and Ctrl + V
Keep in mind that these examples are not recommended for production. In addition there is a problem with the joy cons stop working when using the editor as mentioned at the top of this page.
Modify your <Project Name>.Build.cs
as below:
PublicDependencyModuleNames.AddRange(new string[] {
"Core",
"CoreUObject",
"Engine",
"InputCore",
// Add this as public dependency
"JoyConDriver"
});
PrivateDependencyModuleNames.AddRange(new string[] {
// Add this as private dependency
"InputDevice",
});
// It is recommended to use this code within Begin Play
// Get JoyConDriver module
TArray<IJoyConDriverModule*> JoyConInputApis = IModularFeatures::Get().GetModularFeatureImplementations<IJoyConDriverModule>(IJoyConDriverModule::GetModularFeatureName());
IJoyConDriverModule *JoyConModule; // Add this variable to the UClass that uses the module.
for (IJoyConDriverModule* JoyConInputApi : JoyConInputApis) {
if (JoyConInputApi == nullptr) continue;
if (!JoyConInputApi->IsAvailable()) continue;
JoyConModule = JoyConInputApi;
break;
}
// ...
// ...
if (JoyConModule != nullptr) {
TArray<FJoyConInformation>* FoundControllers = JoyConModule->Get().SearchForJoyCons();
bool UseImu = true; // Use accelerometer and gyroscope
bool UseLocalize = true;
float Alpha = 0.05f;
for (const FJoyConInformation JoyConInfo : *FoundControllers) {
if (JoyConInfo.IsConnected) continue;
int ControllerId = 0;
JoyConModule->Get().ConnectJoyCon(JoyConInfo, UseImu, UseLocalize, Alpha, ControllerId);
}
TArray<FJoyConInformation>* ConnectedControllers = JoyConModule->Get().GetConnectedJoyCons();
int GripIndex = 0; // Set UE4 controller index
for (const FJoyConInformation JoyConInfo : *ConnectedControllers) {
if (JoyConInfo.IsAttached) continue;
JoyConModule->Get().AttachJoyCon(JoyConInfo.ControllerId, GripIndex);
}
}
// ...
// ...
if (JoyConModule != nullptr) {
TArray<FJoyConInformation>* AttachedControllers = JoyConModule->Get().GetAttachedJoyCons();
for (const FJoyConInformation JoyConInfo : *AttachedControllers) {
if (!JoyConInfo.IsAttached) continue;
JoyConModule->Get().DetachJoyCon(JoyConInfo.ControllerId);
}
TArray<FJoyConInformation>* ConnectedControllers = JoyConModule->Get().GetConnectedJoyCons();
for (const FJoyConInformation JoyConInfo : *ConnectedControllers) {
if (!JoyConInfo.IsConnected) continue;
JoyConModule->Get().DisconnectJoyCon(JoyConInfo.ControllerId);
}
}
// ...
// ...
if (JoyConModule != nullptr) {
FRotator Rotation;
int ControllerId = 0;
if (JoyConModule->Get().GetJoyConVector(ControllerId , Rotation)) {
SetActorRotation(Rotation);
}
}
// ...
In the future I plan to add an example with the correct code and try to fix the problem with the editor.
Please do not confuse the Controller Index input with the Array Index output pin inside the for each as it does not contain the correct Device ID and will result in an error.