# Crash when possessing pawn

**URL:** <https://forums.unrealengine.com/t/crash-when-possessing-pawn/369794>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [September 8, 2016, 12:31pm UTC](https://forums.unrealengine.com/t/crash-when-possessing-pawn/369794 "2016-09-08T12:31:20Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![zer0chi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zer0chi](https://forums.unrealengine.com/u/zer0chi)\
**Post date:** [September 8, 2016, 12:31pm UTC](https://forums.unrealengine.com/t/crash-when-possessing-pawn/369794/1 "2016-09-08T12:31:20Z")

</div>

Hello, I have created a character using C++. The code written is for VR. It has basic movement feature and also grab certain objects. Then I tried, using blueprint, to possess a pawn.

 ![106171-controller1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/8/4/c8488d7f6faf1c814184ca6386616b3265b3b5f5.png)

 ![106172-controller2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/d/3/5d331c5e63ed2b03f2e162eaf8771f9d34355964.png)

But for some reason it crashes. If I run the same code but instead of possessing from my VRCharacter I posses from some other pawn, then possession is successful. Why does that happen? What can be the possible reasons for it? Any suggestion would be helpful. If code is needed I can provide that too.

Regards

---

<div class="post-metadata">

**Author:** ![Chownas](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chownas](https://forums.unrealengine.com/u/Chownas)\
**Post date:** [September 8, 2016, 12:40pm UTC](https://forums.unrealengine.com/t/crash-when-possessing-pawn/369794/2 "2016-09-08T12:40:58Z")

</div>

Did you check with an “IsValid” Node if the Character you try to possess is actually, well, valid?

---

<div class="post-metadata">

**Author:** ![zer0chi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zer0chi](https://forums.unrealengine.com/u/zer0chi)\
**Post date:** [September 8, 2016, 12:44pm UTC](https://forums.unrealengine.com/t/crash-when-possessing-pawn/369794/3 "2016-09-08T12:44:26Z")

</div>

Tested it with “IsValid” on your suggestion. Still crashing.

---

<div class="post-metadata">

**Author:** ![Chownas](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Chownas](https://forums.unrealengine.com/u/Chownas)\
**Post date:** [September 8, 2016, 12:50pm UTC](https://forums.unrealengine.com/t/crash-when-possessing-pawn/369794/4 "2016-09-08T12:50:42Z")

</div>

Could you try to give the Target-input on your Possess node the output of GetPlayerController?

---

<div class="post-metadata">

**Author:** ![zer0chi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zer0chi](https://forums.unrealengine.com/u/zer0chi)\
**Post date:** [September 8, 2016, 12:53pm UTC](https://forums.unrealengine.com/t/crash-when-possessing-pawn/369794/5 "2016-09-08T12:53:01Z")

</div>

the code is in Controller class. Do you want me to try it in this class or move the code to GameMode?

---

<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:** [September 8, 2016, 12:56pm UTC](https://forums.unrealengine.com/t/crash-when-possessing-pawn/369794/6 "2016-09-08T12:56:36Z")

</div>

Hey,

Can you post the crash log?

Thanks.

---

<div class="post-metadata">

**Author:** ![zer0chi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zer0chi](https://forums.unrealengine.com/u/zer0chi)\
**Post date:** [September 8, 2016, 1:00pm UTC](https://forums.unrealengine.com/t/crash-when-possessing-pawn/369794/7 "2016-09-08T13:00:55Z")

</div>

Here it is:-

```
MachineId:0A5724804E422E69B5DD0FA03D52BB7B
EpicAccountId:542acf2ff56347d3b52f5c554f92ed63

Access violation - code c0000005 (first/second chance not available)

[rest attached as text][link text][1]

```

---

<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:** [September 8, 2016, 1:07pm UTC](https://forums.unrealengine.com/t/crash-when-possessing-pawn/369794/8 "2016-09-08T13:07:30Z")

</div>

That’s OK. In the future you can upload the .txt files instead of pasting the text in them, if you want.

Can you post the following function:

```
AVRCharacter::MoveForward()

```

---

<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:** [September 8, 2016, 1:11pm UTC](https://forums.unrealengine.com/t/crash-when-possessing-pawn/369794/9 "2016-09-08T13:11:43Z")

</div>

Hey,

Can you post the following function?

```
AVRCharacter::MoveForward()

```

Thanks

---

<div class="post-metadata">

**Author:** ![zer0chi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zer0chi](https://forums.unrealengine.com/u/zer0chi)\
**Post date:** [September 8, 2016, 1:26pm UTC](https://forums.unrealengine.com/t/crash-when-possessing-pawn/369794/10 "2016-09-08T13:26:41Z")

</div>

Well you were right on spot. I recreated the class again. Added parts of code to see where error is.

```
void ATestForPossession::MoveForward(float Value)
{
	/*FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::X);
	AddMovementInput(Direction, Value);*/
}

void ATestForPossession::MoveRight(float Value)
{
	/*FVector Direction = FRotationMatrix(Controller->GetControlRotation()).GetScaledAxis(EAxis::Y);
	AddMovementInput(Direction, Value);*/
}

```

MoveForward and Move Right are creating the problem. Though I am unable to understand why.

Edit: I commented them because those lines are what were crashing the engine when possessing.

---

<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:** [September 8, 2016, 1:35pm UTC](https://forums.unrealengine.com/t/crash-when-possessing-pawn/369794/11 "2016-09-08T13:35:04Z")

</div>

Hey,

Can you try this?

```
 void ATestForPossession::MoveForward(float Value)
 {
	if( Controller )
	{
		FVector Direction = FRotationMatrix( Controller->GetControlRotation( ) ).GetScaledAxis( EAxis::X );
		AddMovementInput( Direction, Value );
	}
 }
 
 void ATestForPossession::MoveRight(float Value)
 {
	if( Controller )
	{
		FVector Direction = FRotationMatrix( Controller->GetControlRotation( ) ).GetScaledAxis( EAxis::Y );
		AddMovementInput( Direction, Value );
	}
 }

```

Also, to explain what is going on:

You are trying to use “Controller” when it might not exist, resulting in a Access Violation; in “easy” terms, a Access Violation is when the program during runtime tries to use a nullptr (a pointer with an empty value). When this happens, the program will terminate with the error you are getting.

In the future, I recommend checking to make sure any pointer you are using that may not be assigned yet or may lose an assignment. As such:

```
if( MyPointer )
{
    // Pointer Exists
}
else
{
    // Pointer doesnt exist
}

```

---

<div class="post-metadata">

**Author:** ![zer0chi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zer0chi](https://forums.unrealengine.com/u/zer0chi)\
**Post date:** [September 8, 2016, 1:39pm UTC](https://forums.unrealengine.com/t/crash-when-possessing-pawn/369794/12 "2016-09-08T13:39:40Z")

</div>

Oh wow thanks a lot. And I feel kinda stupid :P. I messed up at a very basic level. Guess that’s what you get for not programming for a while. This has been a good lesson.

---

<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:** [September 8, 2016, 1:51pm UTC](https://forums.unrealengine.com/t/crash-when-possessing-pawn/369794/13 "2016-09-08T13:51:36Z")

</div>

As an alternative, the way input is done for most generic characters, is as follows:

```
[.h]

void Forward( float Amount );
void Right( float Amount );

[cpp]

void MyCharacter::Forward( float Amount )
{
	if( Amount != 0.f )
	{
		AddMovementInput( GetActorForwardVector( ), Amount );
	}
}

void MyCharacter::Right( float Amount )
{
	if( Amount != 0.f )
	{
		AddMovementInput( GetActorRightVector( ), Amount );
	}
}

```

Good luck with your project.
