# Where are instances of Default PlayerControllers and Pawns created in GameMode?

**URL:** <https://forums.unrealengine.com/t/where-are-instances-of-default-playercontrollers-and-pawns-created-in-gamemode/336551>\
**Category:** Character & Animation\
**Tags:** gamemode, playercontroller, unreal-engine, pawn, question, CPP\
**Created:** [October 26, 2015, 4:05pm UTC](https://forums.unrealengine.com/t/where-are-instances-of-default-playercontrollers-and-pawns-created-in-gamemode/336551 "2015-10-26T16:05:10Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_9437ee0d1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_9437ee0d1](https://forums.unrealengine.com/u/anonymous_user_9437ee0d1)\
**Post date:** [October 26, 2015, 4:05pm UTC](https://forums.unrealengine.com/t/where-are-instances-of-default-playercontrollers-and-pawns-created-in-gamemode/336551/1 "2015-10-26T16:05:10Z")

</div>

Hello,

I’d like to control the spawning of the default PlayerControllers and Pawns that I’m setting in the GameMode constructor but I don’t know which function would be optimal to override. The reason is that I want to do further setup on the one instance of Controller and Pawn I make. Is there a specific function that I should look into?

---

<div class="post-metadata">

**Author:** ![Moss](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/moss/32/704032_2.png) [@Moss](https://forums.unrealengine.com/u/Moss)\
**Post date:** [October 26, 2015, 4:17pm UTC](https://forums.unrealengine.com/t/where-are-instances-of-default-playercontrollers-and-pawns-created-in-gamemode/336551/2 "2015-10-26T16:17:01Z")

</div>

Do you want to change the default classes or do you want to hook into the processes where those are getting spawned?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_9437ee0d1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_9437ee0d1](https://forums.unrealengine.com/u/anonymous_user_9437ee0d1)\
**Post date:** [October 26, 2015, 4:20pm UTC](https://forums.unrealengine.com/t/where-are-instances-of-default-playercontrollers-and-pawns-created-in-gamemode/336551/3 "2015-10-26T16:20:11Z")

</div>

I’d like to hook into the processes where those are getting spawned. Basically, looking for where something like this is called, (Note: don’t know what it would look like but something like this)

`playerController = NewDefaultPlayerController()`

`playerController->setPawn( NewDefaultPawn() )`

note: can’t seem to make template brackets.

---

<div class="post-metadata">

**Author:** ![Moss](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/moss/32/704032_2.png) [@Moss](https://forums.unrealengine.com/u/Moss)\
**Post date:** [October 26, 2015, 5:30pm UTC](https://forums.unrealengine.com/t/where-are-instances-of-default-playercontrollers-and-pawns-created-in-gamemode/336551/4 "2015-10-26T17:30:13Z")

</div>

### Hooking into the spawning process of a PlayerController

To hook into the process when the GameMode spawns you PlayerController you can override the following method in which the GameMode does the actual spawning:

```
/** 
 * Spawns a PlayerController at the specified location; split out from Login()/HandleSeamlessTravelPlayer() for easier overriding 
 *
 * @param RemoteRole the role this controller will play remotely
 * @param SpawnLocation location in the world to spawn
 * @param SpawnRotation rotation to set relative to the world
 *
 * @return PlayerController for the player, NULL if there is any reason this player shouldn't exist or due to some error
 */
virtual APlayerController* SpawnPlayerController(ENetRole InRemoteRole, FVector const& SpawnLocation, FRotator const& SpawnRotation);

```

You can also override the following which will get called just after the GameMode has spawned a new PlayerController or after a SeamlessTravel (I recommend hooking your logic into the next function):

```
/**
 * handles all player initialization that is shared between the travel methods
 * (i.e. called from both PostLogin() and HandleSeamlessTravelPlayer())
 */
virtual void GenericPlayerInitialization(AController* C);

```

### Hooking into the spawning process of your Pawn aka Character

The spawning process will try to spawn a Pawn aka Character at a given PlayerStart, you will be able to modify the final class implementing the following BlueprintNativeEvent.

```
/** returns default pawn class for given controller */
UFUNCTION(BlueprintNativeEvent, Category="Game")
UClass* GetDefaultPawnClassForController(AController* InController);

```

To override the base event just add the following to your header class and add the implementation into your cpp, remember to call the Super.

```
virtual UClass* GetDefaultPawnClassForController_Implementation(AController* InController) override;

```

And to control the actual spawning process you have to implement the following BlueprintNativeEvent (just add the implementation but not the declaration into your header):

```
/**
 * @param	NewPlayer - Controller for whom this pawn is spawned
 * @param	StartSpot - PlayerStart at which to spawn pawn
 * @return	a pawn of the default pawn class
 */
UFUNCTION(BlueprintNativeEvent, Category="Game")
APawn* SpawnDefaultPawnFor(AController* NewPlayer, class AActor* StartSpot);

```

To override the base event just add the following to your header class and add the implementation into your cpp, remember to call the Super.

```
virtual APawn* SpawnDefaultPawnFor_ImplementationAController* NewPlayer, class AActor* StartSpot) override;

```

You should be good to got with those hooks.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_9437ee0d1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_9437ee0d1](https://forums.unrealengine.com/u/anonymous_user_9437ee0d1)\
**Post date:** [October 26, 2015, 5:36pm UTC](https://forums.unrealengine.com/t/where-are-instances-of-default-playercontrollers-and-pawns-created-in-gamemode/336551/5 "2015-10-26T17:36:32Z")

</div>

Thanks so much. I really appreciate the answer and the speed 🙂

---

<div class="post-metadata">

**Author:** ![Moss](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/moss/32/704032_2.png) [@Moss](https://forums.unrealengine.com/u/Moss)\
**Post date:** [October 26, 2015, 5:38pm UTC](https://forums.unrealengine.com/t/where-are-instances-of-default-playercontrollers-and-pawns-created-in-gamemode/336551/6 "2015-10-26T17:38:48Z")

</div>

If it works for you remember to accept the answer ^^

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_9437ee0d1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_9437ee0d1](https://forums.unrealengine.com/u/anonymous_user_9437ee0d1)\
**Post date:** [October 27, 2015, 2:04pm UTC](https://forums.unrealengine.com/t/where-are-instances-of-default-playercontrollers-and-pawns-created-in-gamemode/336551/7 "2015-10-27T14:04:36Z")

</div>

Actually, after reading a bit more, I understand that SpawnDefaultPawnFor needs to be “implemented”, like you said but it’s never called. My controller function is called but my SpawnDefaultPawnFor\_Implementation is never called. Any ideas would be much appreciated.

---

<div class="post-metadata">

**Author:** ![Moss](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/moss/32/704032_2.png) [@Moss](https://forums.unrealengine.com/u/Moss)\
**Post date:** [October 27, 2015, 2:25pm UTC](https://forums.unrealengine.com/t/where-are-instances-of-default-playercontrollers-and-pawns-created-in-gamemode/336551/8 "2015-10-27T14:25:56Z")

</div>

That’s strange, I’ll prepare a test once I’m back home.

---

<div class="post-metadata">

**Author:** ![Moss](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/moss/32/704032_2.png) [@Moss](https://forums.unrealengine.com/u/Moss)\
**Post date:** [October 28, 2015, 7:35am UTC](https://forums.unrealengine.com/t/where-are-instances-of-default-playercontrollers-and-pawns-created-in-gamemode/336551/9 "2015-10-28T07:35:19Z")

</div>

Ok, I missed a small thing when overriding BlueprintNativeEvents, you have to declare the override of your implementation in your header. I’ll update the answer according ^^.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_9437ee0d1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_9437ee0d1](https://forums.unrealengine.com/u/anonymous_user_9437ee0d1)\
**Post date:** [October 28, 2015, 11:38am UTC](https://forums.unrealengine.com/t/where-are-instances-of-default-playercontrollers-and-pawns-created-in-gamemode/336551/10 "2015-10-28T11:38:41Z")

</div>

So that is what I did, but it doesn’t seem to be called. I wrote the implementation function as an override in the header and defined it in the cpp but when I step through the editor at runtime, the SpawnPlayerController function is called but my breakpoint in the SpawnDefaultPawnFor\_Implementation is skipped completely.

---

<div class="post-metadata">

**Author:** ![Moss](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/moss/32/704032_2.png) [@Moss](https://forums.unrealengine.com/u/Moss)\
**Post date:** [October 28, 2015, 1:36pm UTC](https://forums.unrealengine.com/t/where-are-instances-of-default-playercontrollers-and-pawns-created-in-gamemode/336551/11 "2015-10-28T13:36:40Z")

</div>

Might it be that your BP is not calling the parent function?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_9437ee0d1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_9437ee0d1](https://forums.unrealengine.com/u/anonymous_user_9437ee0d1)\
**Post date:** [October 28, 2015, 1:58pm UTC](https://forums.unrealengine.com/t/where-are-instances-of-default-playercontrollers-and-pawns-created-in-gamemode/336551/12 "2015-10-28T13:58:35Z")

</div>

Very well could be. The only way this function is called is through blueprints?

---

<div class="post-metadata">

**Author:** ![Moss](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/moss/32/704032_2.png) [@Moss](https://forums.unrealengine.com/u/Moss)\
**Post date:** [October 28, 2015, 2:34pm UTC](https://forums.unrealengine.com/t/where-are-instances-of-default-playercontrollers-and-pawns-created-in-gamemode/336551/13 "2015-10-28T14:34:55Z")

</div>

No but the call hierarchy is between C++ and BP, so if you do not call the parent/super method you will break the chain somewhere.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_9437ee0d1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_9437ee0d1](https://forums.unrealengine.com/u/anonymous_user_9437ee0d1)\
**Post date:** [October 28, 2015, 2:37pm UTC](https://forums.unrealengine.com/t/where-are-instances-of-default-playercontrollers-and-pawns-created-in-gamemode/336551/14 "2015-10-28T14:37:44Z")

</div>

In the c++, I call the super method inside the “implementation” like so…

```
APawn* ALexusGameMode::SpawnDefaultPawnFor_Implementation( AController* NewPlayer, AActor* StartSpot )
{
	auto pawn = Cast<AnotherPawn>( Super::SpawnDefaultPawnFor( NewPlayer, StartSpot ) );
        // further setup here.
	return pawn;
}

```

---

<div class="post-metadata">

**Author:** ![Moss](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/moss/32/704032_2.png) [@Moss](https://forums.unrealengine.com/u/Moss)\
**Post date:** [October 28, 2015, 3:50pm UTC](https://forums.unrealengine.com/t/where-are-instances-of-default-playercontrollers-and-pawns-created-in-gamemode/336551/15 "2015-10-28T15:50:45Z")

</div>

And you do not have any BP that implements that function?
