# MotionController Input for multi player

**URL:** <https://forums.unrealengine.com/t/motioncontroller-input-for-multi-player/55844>\
**Category:** XR Development\
**Tags:** unreal-engine\
**Created:** [February 19, 2016, 12:00am UTC](https://forums.unrealengine.com/t/motioncontroller-input-for-multi-player/55844 "2016-02-19T00:00:52Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![S\_Q\_R](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@S\_Q\_R](https://forums.unrealengine.com/u/S_Q_R)\
**Post date:** [October 25, 2018, 3:32pm UTC](https://forums.unrealengine.com/t/motioncontroller-input-for-multi-player/55844/13 "2018-10-25T15:32:29Z")

</div>

Hi guys. I got the same issue and I managed to fix it in quite simple way.  
First I did some research and I found many threads about the same problem. I post them at the end of the post so you can make some additional reading if you want to.

So in UMotionControllerComponent inside the PollControllerState method there is an authority check…

```auto

  
if (IsInGameThread())
{
     // Cache state from the game thread for use on the render thread
     const AActor* MyOwner = GetOwner();
     const APawn* MyPawn = Cast<APawn>(MyOwner);
     bHasAuthority = MyPawn ? MyPawn->IsLocallyControlled() : (MyOwner->Role == ENetRole::ROLE_Authority);
}

if (bHasAuthority)
    {
        TArray<IMotionController*> MotionControllers = IModularFeatures::Get().GetModularFeatureImplementations<IMotionController>(IMotionController::GetModularFeatureName());
        for (auto MotionController : MotionControllers)
        {.....

```

Authority check in here is not enough because what we do later is telling the engine to get all motion controllers out there and process them. So if one of them got authority you still update them all.  
PollControllerState is a private method so you cannot edit definition of that method. So instead I wrote this piece of code inside the TickComponent in my UMotionControllerComponent derived class

```auto

void UNetworkMotionControllerComponent::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction)
{
    Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
    const AActor* MyOwner = GetOwner();
    const APawn* MyPawn = Cast<APawn>(MyOwner);
    bHasAuthority = MyPawn ? MyPawn->IsLocallyControlled() : throw;
    if (bHasAuthority == false)
    {
        SetAssociatedPlayerIndex(-1);
// this line is where we tell the engine to not to use this controller. PlayerIndex variable is used differently in platform specific places. eg. SteamVR uses some 2 dimensional array to store the controllers and then only checks if they are smaller than the max value so it can be a better solution to set it to maximum value of int instead. You have to check it up with your platform. (-1 works well with oculus rift and htc vive)
    }

    if (bIsActive&&PlayerIndex == 0)
    {
        FVector Position;
        FRotator Orientation;
        float WorldToMeters = GetWorld() ? GetWorld()->GetWorldSettings()->WorldToMeters : 100.0f;
        const bool bNewTrackedState = PollControllerState(Position, Orientation, WorldToMeters);
        if (bNewTrackedState)
        {
            Server_SetRelativeLocationAndRotation(Position, Orientation);
            //SetRelativeLocationAndRotation(Position, Orientation);
        }
//rest of the default motioncontrollercomponent's code

```

So basically you have to do those things:

1. set PlayerIndex != 0 on the controllers that should’t get the data from you motion controller.
2. implement the function that will set the position and rotation. It have to be done on server so the other clients can see it. I copied the code from USceneComponent::SetRelativeLocationAndRotation() and it woks like a charm.

Please keep in mind that this is the working solution but its like alpha alpha version. I’m sure I’ll try to optimize this so I don’t have to do all those casting inside of a tick function and get rid of the throwing exceptions when there is no Pawn. Do not use this as ready to go solution in your projects. I posted this only as a reference so you can get on going with your projects if you stucked.

Links to read if you want to get more information:

[https://forums.unrealengine.com/development-discussion/vr-ar-development/79167-motion-controllers-and-networking](https://forums.unrealengine.com/development-discussion/vr-ar-development/79167-motion-controllers-and-networking)  
[https://forums.unrealengine.com/development-discussion/vr-ar-development/73125-motioncontroller-input-for-multi-player](https://forums.unrealengine.com/development-discussion/vr-ar-development/73125-motioncontroller-input-for-multi-player)

> **[Motion Controller in Multiplayer: one rules them all](https://forums.unrealengine.com/questions/439041/motion-controller-in-multiplayer-one-rules-them-al.html)**
>
> Hi, As mentioned here on the forum, when you use Motion Controllers Components (here HTC Vive) in multiplayer mode, one of the players movements are used by all the clients! It complicates a lot multiplayer programming while in VR. Is there any fix...

[https://forums.unrealengine.com/development-discussion/vr-ar-development/79167-motion-controllers-and-networking?107140-Motion-controllers-and-networking=](https://forums.unrealengine.com/development-discussion/vr-ar-development/79167-motion-controllers-and-networking?107140-Motion-controllers-and-networking=)  
[VR: Cameras, Multiplayer, Tips & Tricks | Live Training | Unreal Engine - YouTube](https://www.youtube.com/watch?v=jVdFpuicptQ) at 14:35  
and the thread about this livestream  
[Training Stream - Sam and Wes' VR Stream: Cameras, Multiplayer, Tips and Tricks! - Live from Epic HQ - Announcements - Unreal Engine Forums](https://forums.unrealengine.com/unreal-engine/events/71433-training-stream-sam-and-wes-vr-stream-cameras-multiplayer-tips-and-tricks-live-from-epic-hq?99586=)

---

_[View the full topic](https://forums.unrealengine.com/t/motioncontroller-input-for-multi-player/55844)._
