# Having some trouble with a multiplayer tutorial

**URL:** <https://forums.unrealengine.com/t/having-some-trouble-with-a-multiplayer-tutorial/90259>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [April 19, 2017, 4:31pm UTC](https://forums.unrealengine.com/t/having-some-trouble-with-a-multiplayer-tutorial/90259 "2017-04-19T16:31:15Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_8de2a944](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8de2a944](https://forums.unrealengine.com/u/anonymous_user_8de2a944)\
**Post date:** [April 19, 2017, 4:31pm UTC](https://forums.unrealengine.com/t/having-some-trouble-with-a-multiplayer-tutorial/90259/1 "2017-04-19T16:31:15Z")

</div>

Hi! I’m working on a game for a class project. I’m new to C++ and Unreal Engine, and I’ve been doing fine so far using tutorials, but now I’ve run into something that’s stumped me.

I’ve been using the following information to attempt to make a multiplayer where two players can use the same keyboard (one with WASD, one with arrow keys).

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — https://unrealcommunity.wiki/! You will be able to find content from...

There’s a bit of code that isn’t working so far, though:

int32 id = GetLocalPlayer()-\>GetControllerId();

The compiler doesn’t appear to recognize GetLocalPlayer(), and when I try other things, I get a “nonstatic member function must be relative to a specific object” error, and when I make it relative to a specific object it isn’t an int32 and I get an error in the next line. I’ve looked at everything on google that’s even remotely related but none of the solutions seem to apply (or if they do apply, they’re above my current level of understanding and not specific enough for me to know how to implement them).

The one problem I can think of is that I’ve included Engine.h in my Avatar class rather than “the main header file” as the tutorial recommends, but I have no idea what it’s referring to with regards to the main header file, I wasn’t able to find an answer on google, and I wasn’t able to find the “EngineMinimal.h” I was supposed to replace anywhere in the project.

Is there a simple solution to this problem, or should I find a different way to implement local multiplayer on one keyboard? Using gamepads isn’t an option.

I really appreciate any help – it won’t affect my grade if I can’t figure out this multiplayer, but I think it’s essential to the game and I’m determined to figure it out if it’s the last thing I do. Thank you!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_61b4a355](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_61b4a355](https://forums.unrealengine.com/u/anonymous_user_61b4a355)\
**Post date:** [April 19, 2017, 5:15pm UTC](https://forums.unrealengine.com/t/having-some-trouble-with-a-multiplayer-tutorial/90259/2 "2017-04-19T17:15:54Z")

</div>

Your main header file is named the same as your project. As an example, if your project is named “Shooter”, your main header would be Shooter.h.

Depending on how you set your project up, EngineMinimal.h may be included; though it could be Engine.h.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8de2a944](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8de2a944](https://forums.unrealengine.com/u/anonymous_user_8de2a944)\
**Post date:** [April 20, 2017, 1:22am UTC](https://forums.unrealengine.com/t/having-some-trouble-with-a-multiplayer-tutorial/90259/3 "2017-04-20T01:22:35Z")

</div>

Thank you for your quick response! That is helpful, and I was able to find the main header file. However, it looks like Engine.h is already included, so that can’t be the problem.

Here’s the code in the SetupPlayerInputComponent section that is giving me an error:

int32 id = GetLocalPlayer()-\>GetControllerId();  
if (id == 0)  
{  
InputComponent-\>BindAxis(“Forward\_P1”, this, &APlayerAvatar::MoveForward);  
InputComponent-\>BindAxis(“Strafe\_P1”, this, &APlayerAvatar::TurnRight);  
}  
else if (id == 1)  
{  
InputComponent-\>BindAxis(“Forward\_P2”, this, &APlayerAvatar::MoveForward);  
InputComponent-\>BindAxis(“Strafe\_P2”, this, &APlayerAvatar::TurnRight);  
}

“GetLocalPlayer()” is giving me the error ‘identifier “GetLocalPlayer” is undefined.’ However, when I go to the definition, it exists in PlayerController.h. Is there a reason I’m running into this problem? Apologies if this is a really simple C++ issue; I’m very new to this.

Thanks again for your help!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_61b4a355](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_61b4a355](https://forums.unrealengine.com/u/anonymous_user_61b4a355)\
**Post date:** [April 20, 2017, 2:14pm UTC](https://forums.unrealengine.com/t/having-some-trouble-with-a-multiplayer-tutorial/90259/4 "2017-04-20T14:14:15Z")

</div>

Are you calling SetupPlayerInputComponent from the Character?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8de2a944](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8de2a944](https://forums.unrealengine.com/u/anonymous_user_8de2a944)\
**Post date:** [April 20, 2017, 6:31pm UTC](https://forums.unrealengine.com/t/having-some-trouble-with-a-multiplayer-tutorial/90259/5 "2017-04-20T18:31:18Z")

</div>

Yes, I am. Everything else about SetupPlayerInputComponent is working perfectly, and I don’t have any issues in single player at all. It’s only when I have that line with GetLocalPlayer() that I get an error.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_61b4a355](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_61b4a355](https://forums.unrealengine.com/u/anonymous_user_61b4a355)\
**Post date:** [April 20, 2017, 6:40pm UTC](https://forums.unrealengine.com/t/having-some-trouble-with-a-multiplayer-tutorial/90259/6 "2017-04-20T18:40:50Z")

</div>

I don’t believe the Pawn/Character has the GetLocalPlayer( ) function.

You will need to get the local player from the characters player controller, like:

```auto

APlayerController *PC = Cast<APlayerController>(GetController( ));
if(PC)
{
    ULocalPlayer *LocalPlayer = PC->GetLocalPlayer( );
    if(LocalPlayer)
   {
       int32 id = LocalPlayer->GetControllerId( );
       if(id == 0)
       {
       }
       else if(id == 1)
       {
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_8de2a944](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_8de2a944](https://forums.unrealengine.com/u/anonymous_user_8de2a944)\
**Post date:** [April 21, 2017, 12:21am UTC](https://forums.unrealengine.com/t/having-some-trouble-with-a-multiplayer-tutorial/90259/7 "2017-04-21T00:21:06Z")

</div>

It works! Thank you so much, Kyle! You’re a lifesaver.
