# How Can I prevent Controlled Pawns from Being Deleted On Reset?

**URL:** <https://forums.unrealengine.com/t/how-can-i-prevent-controlled-pawns-from-being-deleted-on-reset/1155374>\
**Category:** Programming & Scripting\
**Tags:** reset, unreal-engine, question\
**Created:** [May 5, 2023, 1:25pm UTC](https://forums.unrealengine.com/t/how-can-i-prevent-controlled-pawns-from-being-deleted-on-reset/1155374 "2023-05-05T13:25:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoeProgram](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/joeprogram/32/872486_2.png) [@JoeProgram](https://forums.unrealengine.com/u/JoeProgram)\
**Post date:** [May 5, 2023, 1:25pm UTC](https://forums.unrealengine.com/t/how-can-i-prevent-controlled-pawns-from-being-deleted-on-reset/1155374/1 "2023-05-05T13:25:02Z")

</div>

![local_multiplayer](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/3/3/233af05ecbcf1a90de169cd246e59098c2c235aa.jpeg)

I’m working a local multiplayer game. At the end of the round, I’d like to reset it so players are ready to play again. I’m using the `Reset Level` node and the `OnReset` event.

![output](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/1/3/d137d6eda2ca8c5a46577c45641eddf3b79df48f.gif)

I’m seeing two things happen when I reset the level:

1. Any pawn possessed by a player controller is deleted
2. The camera changes

![output](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/c/2/cc27c2343a520c67b297cf1af2fd6311af9e95c8.gif)

For example, if I have 4 player controllers that each possess a pawn, all 4 pawns are deleted `OnReset`

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/b/0/cb09f5de58037a6818945aacb41e83e60efaa42d.jpeg "WTF Is? Reset Level in Unreal Engine 4 ( UE4 )") ](https://www.youtube.com/watch?v=LseY59ffKK8)

In Mathew Wadstein’s video on this, he calls out a similar, but subtly different behavior:  
He notes the issue that any player pawn spawned in by the player start will be deleted. However, my pawns are not spawned in by player starts - they are in the level directly.

 ![temporary_possession](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/6/5/465f581bc35ab3200b86673f739733c53bd9ad96.png)

In the comments section to that video, devs say they’ve worked around this by spawning a default pawn, having the player controller possess that, resetting the level, then restoring the original connection. So far, that hasn’t worked for me - the berry is still deleted when this blueprint code is run.

Any advice on how I can keep these pawns from being deleted `OnReset`?

---

<div class="post-metadata">

**Author:** ![JoeProgram](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/joeprogram/32/872486_2.png) [@JoeProgram](https://forums.unrealengine.com/u/JoeProgram)\
**Post date:** [May 5, 2023, 2:01pm UTC](https://forums.unrealengine.com/t/how-can-i-prevent-controlled-pawns-from-being-deleted-on-reset/1155374/2 "2023-05-05T14:01:04Z")

</div>

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/b/5/7b5bc35e84f814aa34b34a7f0df7a9232c9cee62.jpeg "Unreal Engine 5 Tutorial - How to Reset Level and Reset Player") ](https://www.youtube.com/watch?v=rarolKxJwXQ)

Hm… in this video they show pairing `Reset Level` with `Restart Player at Player Start` and also a `Delay.`

 ![restart_player_at_transform](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/9/a/d9af7f5ff19fa8dc1a72bd88112b7db9271542f8.png)

I’m not using Player Starts in my game, so I swapped it for the “Restart Player at Transform.”

However, I’m not seeing any change in the behavior - the pawn is deleted, the camera changes, and there isn’t a pawn that replaces it.

---

<div class="post-metadata">

**Author:** ![JoeProgram](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/joeprogram/32/872486_2.png) [@JoeProgram](https://forums.unrealengine.com/u/JoeProgram)\
**Post date:** [May 5, 2023, 2:18pm UTC](https://forums.unrealengine.com/t/how-can-i-prevent-controlled-pawns-from-being-deleted-on-reset/1155374/3 "2023-05-05T14:18:47Z")

</div>

![Screenshot 2023-05-05 071724](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/4/5/f45264185ffbaa7b7cceb1c47fc3fe699d20af97.png)

Checking out the C++…

Simply enough, looks like the behavior is different if the controller is set on the pawn. Still not sure why unpossessing the pawn isn’t working for me…

---

<div class="post-metadata">

**Author:** ![JoeProgram](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/joeprogram/32/872486_2.png) [@JoeProgram](https://forums.unrealengine.com/u/JoeProgram)\
**Post date:** [May 6, 2023, 1:55am UTC](https://forums.unrealengine.com/t/how-can-i-prevent-controlled-pawns-from-being-deleted-on-reset/1155374/4 "2023-05-06T01:55:36Z")

</div>

![camera_not_changed](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/4/6/d469948f60e838511364859da3b4c46b3813c0cd.jpeg)  
Interesting - when I select the camera in the Outliner, I can see the view is still correct. So the new view is something different happening.

![PlayerController_Reset](https://d3kjluh73b9h9o.cloudfront.net/original/4X/f/6/1/f613d93f94e00395c35ac94ce1b911f8887e43b4.png)  
Yeah, looks like in the C++ the view target is getting reset.

---

<div class="post-metadata">

**Author:** ![JoeProgram](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/joeprogram/32/872486_2.png) [@JoeProgram](https://forums.unrealengine.com/u/JoeProgram)\
**Post date:** [May 7, 2023, 5:21pm UTC](https://forums.unrealengine.com/t/how-can-i-prevent-controlled-pawns-from-being-deleted-on-reset/1155374/5 "2023-05-07T17:21:12Z")

</div>

Ok, this resetting behavior is built in at a few places in C++:

1. `APawn::Reset()`
2. `APlayerController::Reset()`
3. `APlayerController::ClientReset_Implementation()`

The cleanest solution I find is to make subclasses and override the default behaviors. I made 3:

**ResettablePawn.h**

```auto
#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Pawn.h"
#include "ResettablePawn.generated.h"

UCLASS()
class BUMPERCROP_API AResettablePawn : public APawn
{
	GENERATED_BODY()

public:	

	AResettablePawn(); //constructor

	virtual void Reset() override;

};

```

**ResettablePawn.cpp**

```auto
#include "ResettablePawn.h"
#include "Engine/GameEngine.h"

// constructor
AResettablePawn::AResettablePawn()
{
	PrimaryActorTick.bCanEverTick = true;
}

void AResettablePawn::Reset()
{
	K2_OnReset();
}

```

_(K2\_OnReset() is the function that triggers the Blueprint OnReset event)_

**ResettablePlayerController.h**

```auto
#pragma once

#include "CoreMinimal.h"
#include "GameFramework/PlayerController.h"
#include "ResettablePlayerController.generated.h"

UCLASS()
class BUMPERCROP_API AResettablePlayerController : public APlayerController
{
	GENERATED_BODY()
	
public:

	AResettablePlayerController(); //constructor

	virtual void Reset() override;

};

```

**ResettablePlayerController.cpp**

```auto
#include "ResettablePlayerController.h"

AResettablePlayerController::AResettablePlayerController()
{
	PrimaryActorTick.bCanEverTick = true;

}

void AResettablePlayerController::Reset()
{

	K2_OnReset();

}

```

That takes care of the first two functions, but the third one isn’t virtual. For that one, we can override the GameModeBase::ResetLevel() function, keep most of the code the same, but remove the client reset call.

The client reset would need to be replaced with a different function if the game were networked, but that’s out of scope for now.

**ResettableGameMode.h**

```auto
#pragma once

#include "CoreMinimal.h"
#include "GameFramework/GameMode.h"
#include "ResettableGameMode.generated.h"

/**
 * 
 */
UCLASS()
class BUMPERCROP_API AResettableGameMode : public AGameMode
{
	GENERATED_BODY()
	
public:
	virtual void ResetLevel() override;
};

```

**ResettableGameMode.cpp**

```auto
#include "ResettableGameMode.h"
#include "EngineUtils.h"
#include "Engine/LevelScriptActor.h"

void AResettableGameMode::ResetLevel()
{
	UE_LOG(LogGameMode, Verbose, TEXT("Reset %s"), *GetName());

	// Reset ALL controllers first
	for (FConstControllerIterator Iterator = GetWorld()->GetControllerIterator(); Iterator; ++Iterator)
	{
		AController* Controller = Iterator->Get();
		Controller->Reset();
	}

	// Reset all actors (except controllers, the GameMode, and any other actors specified by ShouldReset())
	for (FActorIterator It(GetWorld()); It; ++It)
	{
		AActor* A = *It;
		if (IsValid(A) && A != this && !A->IsA<AController>() && ShouldReset(A))
		{
			A->Reset();
		}
	}

	// Reset the GameMode
	Reset();

	// Notify the level script that the level has been reset
	ALevelScriptActor* LevelScript = GetWorld()->GetLevelScriptActor();
	if (LevelScript)
	{
		LevelScript->LevelReset();
	}
}

```

Then I just switched the parent classes of my custom Blueprint pawn, player controller, and game mode to these new versions.

* * *

This is perhaps a bit overkill - another option is just creating a new type of Reset that didn’t have these built-in behaviors might be easier, but at least it was good getting practice digging into the engine.
