# 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:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fredrum](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fredrum](https://forums.unrealengine.com/u/Fredrum)\
**Post date:** [February 19, 2016, 12:00am UTC](https://forums.unrealengine.com/t/motioncontroller-input-for-multi-player/55844/1 "2016-02-19T00:00:52Z")

</div>

Hi All,

I am trying to change my setup to allow for two players where each uses motion controllers(hydras for now), using the now standard component.

But I don’t seem to be able to get each player have their own input.  
I have tried setting the ‘Player Index’ to 0 and 1 depending on player game instance but that doesn’t seem to do it.  
The input still flows to both clients’ player Pawns.

I’,m sure this is simple but I can’t seem to find the answer. Anyone?

Cheers

---

<div class="post-metadata">

**Author:** ![getnamo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/getnamo/32/1194624_2.png) [@getnamo](https://forums.unrealengine.com/u/getnamo)\
**Post date:** [February 19, 2016, 12:47pm UTC](https://forums.unrealengine.com/t/motioncontroller-input-for-multi-player/55844/2 "2016-02-19T12:47:00Z")

</div>

Try using an authority switch [A Crash Course in Blueprint Replication - Unreal Engine](https://www.unrealengine.com/blog/crash-course-in-blueprints-replication) before the input gets forwarded. It would be great if someone with multiplayer vive/touch could let us know how it is handled there.

---

<div class="post-metadata">

**Author:** ![Fredrum](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fredrum](https://forums.unrealengine.com/u/Fredrum)\
**Post date:** [February 19, 2016, 5:13pm UTC](https://forums.unrealengine.com/t/motioncontroller-input-for-multi-player/55844/3 "2016-02-19T17:13:26Z")

</div>

Hi Getnamo,

hmm…in this particular setup I just use some cubes to visualize my hands, so there is no actual blueprint or c++ code to do anything further.  
Like so

![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/7/f/77f4eddef774a99bd9636cc28463d0e0bd029a75.png)  
So here there’s no way to add a authority switch right?

I will still try making something now to try what you suggest…  
(as I do more elsewhere)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_70a68998](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_70a68998](https://forums.unrealengine.com/u/anonymous_user_70a68998)\
**Post date:** [February 19, 2016, 5:24pm UTC](https://forums.unrealengine.com/t/motioncontroller-input-for-multi-player/55844/4 "2016-02-19T17:24:43Z")

</div>

I have been trying to find a fix for this for a while now. Last week during Sam and Wes’ VR stream they were talking about how 4.11 has this fixed on the code side and they provided the code to fix it.

```auto

bool UMotionControllerComponent::PollControllerState(FVector& Position, FRotator& Orientation)
{
	if (IsInGameThread())
	{
		// Cache state from the game thread for use on the render thread
		const APlayerController* Actor = Cast<APlayerController>(GetOwner());
		bHasAuthority = !Actor || Actor->IsLocalPlayerController();
	}

```

Also if you watch that twitch stream they talk about how we could possibly implement this code into 4.10 (right after Wes finished the teleport tutorial). I’m not particularly good with coding so I couldnt get it to build properly. If anyone tries this and makes it work can you please post back your process.

---

<div class="post-metadata">

**Author:** ![Fredrum](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fredrum](https://forums.unrealengine.com/u/Fredrum)\
**Post date:** [February 19, 2016, 5:40pm UTC](https://forums.unrealengine.com/t/motioncontroller-input-for-multi-player/55844/5 "2016-02-19T17:40:26Z")

</div>

I just tried to do this but the problem is still the same. The input flows to both Player1 and Player2 pawns.  
I tried using both ‘Authority’ and ‘Remote’.  
It just makes the MC’s work or not in one or the other game instance window.

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/9/a/c9aadd8c0b3955e85d455d9702385466ca7d674a.png)

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_70a68998](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_70a68998](https://forums.unrealengine.com/u/anonymous_user_70a68998)\
**Post date:** [February 19, 2016, 5:51pm UTC](https://forums.unrealengine.com/t/motioncontroller-input-for-multi-player/55844/6 "2016-02-19T17:51:57Z")

</div>

Wes was saying on the stream that there is no Blueprint way of doing it so that’s why its got to be implemented to the motioncontroller code.

---

<div class="post-metadata">

**Author:** ![Fredrum](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fredrum](https://forums.unrealengine.com/u/Fredrum)\
**Post date:** [February 19, 2016, 7:53pm UTC](https://forums.unrealengine.com/t/motioncontroller-input-for-multi-player/55844/7 "2016-02-19T19:53:44Z")

</div>

Hmm…yes I am also trying right now doing it with code instead.

I added a c++ component class inheriting from the standard motion controller.  
But in Visual Studio the .cpp and .h are almost blank so I am not sure what and how to add that bit you posted.

They seemed to say I should be able to just do add code, and not need the full Engine source build, right?

Where did you get that code snippet?

It would be incredibly helpful if anyone could tell us how to do this!?

Cheers

---

<div class="post-metadata">

**Author:** ![getnamo](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/getnamo/32/1194624_2.png) [@getnamo](https://forums.unrealengine.com/u/getnamo)\
**Post date:** [February 21, 2016, 3:13pm UTC](https://forums.unrealengine.com/t/motioncontroller-input-for-multi-player/55844/8 "2016-02-21T15:13:54Z")

</div>

After skimming over this quickly, it appears to be an engine fix. So your best bet is to wait for 4.11 as there isn’t a good way to fix this for plugins that isn’t a workaround.  
If you do want a workaround though, one way would be to get the positions manually (e.g. hydra events) and putting the authority check there before affecting your output/etc, but then you’re not using the motion controller abstraction.

Relevant code changes (line 78):

```auto

bool UMotionControllerComponent::PollControllerState(FVector& Position, FRotator& Orientation)

```

in

[https://github.com/EpicGames/UnrealEngine/blob/master/Engine/Source/Runtime/HeadMountedDisplay/Private/MotionControllerComponent.cpp](https://github.com/EpicGames/UnrealEngine/blob/master/Engine/Source/Runtime/HeadMountedDisplay/Private/MotionControllerComponent.cpp)

---

<div class="post-metadata">

**Author:** ![Fredrum](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Fredrum](https://forums.unrealengine.com/u/Fredrum)\
**Post date:** [February 22, 2016, 5:14pm UTC](https://forums.unrealengine.com/t/motioncontroller-input-for-multi-player/55844/9 "2016-02-22T17:14:52Z")

</div>

@getnamo

On the thread for that twitch stream Wes from Unreal says,

> [@](#):
>
> "You have run into the same hurdle we have regarding multiplayer with motion controllers. Our team has indicated that a code side fix for this is in the 4.11 preview build however after testing, I’m still unable to get this to work properly myself. "

At the moment I have a setup probably something like you suggest, I am using intermediate objects for the tracked motion and have a stop-start filter setup that I can hotkey switch between Player1 and Player2.  
It is not a good solution though and I am afraid that it will cause extra confusion when setting up the multiplayer and replication, if I forget to add this properly at the right places or make any mistakes in my switch setups.

Hoping for a proper in engine solution.

Cheers

---

<div class="post-metadata">

**Author:** ![benicourt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@benicourt](https://forums.unrealengine.com/u/benicourt)\
**Post date:** [April 11, 2016, 2:15pm UTC](https://forums.unrealengine.com/t/motioncontroller-input-for-multi-player/55844/10 "2016-04-11T14:15:46Z")

</div>

Hello,  
I use 4.11.1 version and i still have the same problem.  
I have a replicated variable which contains the transformations of the right Motion Controller.  
Only Server modify this variable  
But, server seems to use only the tranforms of motion controller of the player which is server…

I wonder if motion controllers aren’t “nativelty” replicated when child of a BP which is replicated, and if i have to use “Player index” to obtain the good result ?  
I found that “replicate movement” has an action on these components (not only movement component).

Could you help me ?

---

<div class="post-metadata">

**Author:** ![Deams](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Deams](https://forums.unrealengine.com/u/Deams)\
**Post date:** [April 12, 2016, 9:15am UTC](https://forums.unrealengine.com/t/motioncontroller-input-for-multi-player/55844/11 "2016-04-12T09:15:06Z")

</div>

I had to add network support for motion controllers on a project and I have not seen any native implementation for replication. Ended up writing it from scratch.  
So this shouldn’t be the cause of your issue.

---

<div class="post-metadata">

**Author:** ![benicourt](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@benicourt](https://forums.unrealengine.com/u/benicourt)\
**Post date:** [April 12, 2016, 9:42am UTC](https://forums.unrealengine.com/t/motioncontroller-input-for-multi-player/55844/12 "2016-04-12T09:42:46Z")

</div>

The replication seems to be automatic… when activating replication on the pawn actor.  
It’s a good point… But the bad point is that it uses the Motion controllers of the first pawn… Player Index, a solution ? Maybe, but what number ? Where can i find it ?

---

<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=)
