# \[UE5\] GetSocketLocation returning origin or local position instead of world position

**URL:** <https://forums.unrealengine.com/t/ue5-getsocketlocation-returning-origin-or-local-position-instead-of-world-position/492059>\
**Category:** C++\
**Tags:** socket, unreal-engine, UE5-0, question, UE4-27\
**Created:** [January 28, 2022, 12:49am UTC](https://forums.unrealengine.com/t/ue5-getsocketlocation-returning-origin-or-local-position-instead-of-world-position/492059 "2022-01-28T00:49:37Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_006810ab1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_006810ab1](https://forums.unrealengine.com/u/anonymous_user_006810ab1)\
**Post date:** [January 28, 2022, 12:49am UTC](https://forums.unrealengine.com/t/ue5-getsocketlocation-returning-origin-or-local-position-instead-of-world-position/492059/1 "2022-01-28T00:49:37Z")

</div>

I am trying to spawn a bullet at the world location of a socket, but the bullet is spawning at the map origin. I have always tick pose and refresh bones on both the player and the gun. I’m not sure what else I am missing.

```auto
if (m_MeshRef != nullptr && m_MeshRef->DoesSocketExist("BulletSocket"))//just in case
	{
		spawnLocation = m_MeshRef->GetSocketLocation("BulletSocket");
	}
else
		spawnLocation = GetActorLocation(); // this does work but spawns at the blueprint location, this line is not reached because the above if statement is true

```

I know the bullet spawns because I am currently spawning the bullet from the gun’s location (handle) while I do other things and try to figure out why my socket is not working. I did attempt to check if GetSocketLocation does the same in blueprints by printing the location on screen but all I was able to do was crash unreal. I am a beginner with unreal since I am a new user from C# programming in unity.

Also forum bug, 5-0EA does not work as a version tag???

---

<div class="post-metadata">

**Author:** ![Natalo77](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Natalo77](https://forums.unrealengine.com/u/Natalo77)\
**Post date:** [January 28, 2022, 11:25am UTC](https://forums.unrealengine.com/t/ue5-getsocketlocation-returning-origin-or-local-position-instead-of-world-position/492059/2 "2022-01-28T11:25:21Z")

</div>

Try using `UStaticMeshComponent::GetSocketTransform` instead, as you can specify a world space with it.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_006810ab1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_006810ab1](https://forums.unrealengine.com/u/anonymous_user_006810ab1)\
**Post date:** [January 28, 2022, 5:08pm UTC](https://forums.unrealengine.com/t/ue5-getsocketlocation-returning-origin-or-local-position-instead-of-world-position/492059/3 "2022-01-28T17:08:44Z")

</div>

> [@Natalo77](#):
>
> UStaticMeshComponent::GetSocketTransform

I did try using this function but for some reason using the GetLocation() from the FTransform causes unreal to crash with Unhandled Exception: EXCEPTION\_ACCESS\_VIOLATION reading address 0x0000000000000010 ?

```auto
	FTransform spawnTransform = FTransform();
	if (m_MeshRef != nullptr && m_MeshRef->DoesSocketExist("BulletSocket")) //this does not work?????
	{

		spawnTransform = m_MeshRef->GetSocketTransform("BulletSocket", RTS_World);
		//spawnLocation = m_MeshRef->GetSocketLocation("BulletSocket");
		spawnLocation = spawnTransform.GetLocation(); //crashes here
	}
	else
		spawnLocation = GetActorLocation();

```

Am I missing something important?

and then another crash at the previous line when I tried adding isValid: Unhandled Exception: EXCEPTION\_ACCESS\_VIOLATION reading address 0x0000000000000000

```auto
FTransform spawnTransform = FTransform();
	if (m_MeshRef != nullptr && m_MeshRef->DoesSocketExist("BulletSocket")) //this does not work?????
	{

		spawnTransform = m_MeshRef->GetSocketTransform("BulletSocket", RTS_World);//crashed here
		if(spawnTransform.IsValid())
			spawnLocation = spawnTransform.GetLocation();
	}

```

---

<div class="post-metadata">

**Author:** ![Natalo77](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Natalo77](https://forums.unrealengine.com/u/Natalo77)\
**Post date:** [January 31, 2022, 8:27am UTC](https://forums.unrealengine.com/t/ue5-getsocketlocation-returning-origin-or-local-position-instead-of-world-position/492059/4 "2022-01-31T08:27:38Z")

</div>

I think I’m going to need to see an expanded section of code, perhaps the function you’ve written this in - This doesn’t make any sense.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_006810ab1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_006810ab1](https://forums.unrealengine.com/u/anonymous_user_006810ab1)\
**Post date:** [January 31, 2022, 4:53pm UTC](https://forums.unrealengine.com/t/ue5-getsocketlocation-returning-origin-or-local-position-instead-of-world-position/492059/5 "2022-01-31T16:53:04Z")

</div>

```auto
/// <summary>
/// Shoot weapon
/// </summary>
bool ABaseWeapon::Fire(FVector AimDirection)
{
	//get bullet from bullet pool
	ABaseBullet* bullet = GetBulletFromPool();
	if (bullet == nullptr)
	{
		//error no bullets
		return false;
	}

	bullet->SetBulletInfo(m_BulletInfo);

	//give it a vector and rotate only the X so that it only moves on the YZ plane
	FVector spawnLocation = GetActorLocation();
	FRotator spawnRotation;
	FTransform spawnTransform = FTransform();

	if (m_MeshRef != nullptr && m_MeshRef->DoesSocketExist("BulletSocket"))
	{
		spawnTransform = m_MeshRef->GetSocketTransform("BulletSocket", RTS_World);
		//spawnLocation = m_MeshRef->GetSocketLocation("BulletSocket");
		if(spawnTransform.IsValid())
			spawnLocation = spawnTransform.GetLocation();
	}
		
	spawnRotation = AimDirection.Rotation();

	//tell gameinstance to place a bullet at socket location
	bullet->FireBullet(spawnLocation, spawnRotation);

	return true;
}

```

which is called by player

```auto
void APlayerCharacter::Fire()
{
	if (!CanFire)//player may be in fire animation
		return;

	CanFire = false;//player is firing
	GetAimFrame();//get firing angle

	//shoot bullet from weapon
	m_SpawnedWeapon->Fire(AimVector());

	//animate player firing
}

```

which is called on fire input

```auto
PlayerInputComponent->BindAction("Fire", IE_Pressed, this, &APlayerCharacter::Fire);

```

---

<div class="post-metadata">

**Author:** ![Natalo77](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Natalo77](https://forums.unrealengine.com/u/Natalo77)\
**Post date:** [February 1, 2022, 8:26am UTC](https://forums.unrealengine.com/t/ue5-getsocketlocation-returning-origin-or-local-position-instead-of-world-position/492059/6 "2022-02-01T08:26:59Z")

</div>

This is genuinely bizarre - I have no idea how this wouldn’t work - You said when you tried to use `GetSocketLocation` in blueprints, it crashed?  
Do you have the crash log for that?

---

<div class="post-metadata">

**Author:** ![Jambax](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jambax/32/904177_2.png) [@Jambax](https://forums.unrealengine.com/u/Jambax)\
**Post date:** [February 1, 2022, 9:32am UTC](https://forums.unrealengine.com/t/ue5-getsocketlocation-returning-origin-or-local-position-instead-of-world-position/492059/7 "2022-02-01T09:32:48Z")

</div>

GetSocketLocation returns a world-space Location by default.

However the crash seems to indicate this is an issue with something else. Make sure you are running in DebugGame Editor in Visual Studio, _NOT_ Development Editor or you won’t break in the correct place and debug information will be useless.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_006810ab1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_006810ab1](https://forums.unrealengine.com/u/anonymous_user_006810ab1)\
**Post date:** [February 1, 2022, 5:07pm UTC](https://forums.unrealengine.com/t/ue5-getsocketlocation-returning-origin-or-local-position-instead-of-world-position/492059/8 "2022-02-01T17:07:00Z")

</div>

From what I could recall it was the same error and I tried a few times with the same result. I can try again though to check.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_006810ab1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_006810ab1](https://forums.unrealengine.com/u/anonymous_user_006810ab1)\
**Post date:** [February 1, 2022, 5:09pm UTC](https://forums.unrealengine.com/t/ue5-getsocketlocation-returning-origin-or-local-position-instead-of-world-position/492059/9 "2022-02-01T17:09:06Z")

</div>

For some reason GetSocketLocation is not returning the expected location. I assume the socket that I put inside the gun skeleton does not detatch? At least I don’t touch it in code after I added it. when the player walks around with the gun, the bullets still come from the origin and do not change position at all.

I will check the Visual Studio thing and see if I can get better debug information.

Well it was on development editor so I switched it and tried again, but I got the same crash Unhandled Exception: EXCEPTION\_ACCESS\_VIOLATION reading address 0x0000000000000000

I found the crash log though so here is the full error

[2022.02.01-17.26.34:067][756]LogWindows: Error: === Critical error: ===  
[2022.02.01-17.26.34:067][756]LogWindows: Error:  
[2022.02.01-17.26.34:067][756]LogWindows: Error: Fatal error!  
[2022.02.01-17.26.34:067][756]LogWindows: Error:  
[2022.02.01-17.26.34:067][756]LogWindows: Error: Unhandled Exception: EXCEPTION\_ACCESS\_VIOLATION reading address 0x0000000000000000  
[2022.02.01-17.26.34:067][756]LogWindows: Error:  
[2022.02.01-17.26.34:067][756]LogWindows: Error: [Callstack] 0x00007ff87441594d UnrealEditor-GunslingerUE5.dll!ABaseWeapon::Fire() [C:[redacted]\GunslingerUnreal\Source\GunslingerUE5\Private\BaseWeapon.cpp:80]  
[2022.02.01-17.26.34:067][756]LogWindows: Error: [Callstack] 0x00007ff87441bd22 UnrealEditor-GunslingerUE5.dll!APlayerCharacter::Fire() [C:[Redacted]\GunslingerUnreal\Source\GunslingerUE5\PlayerCharacter.cpp:143]  
[2022.02.01-17.26.34:067][756]LogWindows: Error: [Callstack] 0x00007ff887c3ae2a UnrealEditor-Engine.dll!UnknownFunction []  
[2022.02.01-17.26.34:067][756]LogWindows: Error: [Callstack] 0x00007ff887c6c10e UnrealEditor-Engine.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff8876e6f6b UnrealEditor-Engine.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff8876fbd61 UnrealEditor-Engine.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff8876e5249 UnrealEditor-Engine.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff8876fac0d UnrealEditor-Engine.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff886506826 UnrealEditor-Engine.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff887b0a11e UnrealEditor-Engine.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff887b1189f UnrealEditor-Engine.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff8bacc15ea UnrealEditor-Core.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff8bacc1a6e UnrealEditor-Core.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff8bacd3d43 UnrealEditor-Core.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff887b2fd11 UnrealEditor-Engine.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff887b3647d UnrealEditor-Engine.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff886f2895f UnrealEditor-Engine.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff886f32447 UnrealEditor-Engine.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff8a2fce9c0 UnrealEditor-UnrealEd.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff8a38ecc16 UnrealEditor-UnrealEd.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff732f48930 UnrealEditor.exe!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff732f60b2c UnrealEditor.exe!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff732f60c0a UnrealEditor.exe!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff732f7573d UnrealEditor.exe!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff732f786ba UnrealEditor.exe!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff90c767034 KERNEL32.DLL!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error: [Callstack] 0x00007ff90cfc2651 ntdll.dll!UnknownFunction []  
[2022.02.01-17.26.34:069][756]LogWindows: Error:  
[2022.02.01-17.26.34:093][756]LogThreadingWindows: Error: Runnable thread StallDetectorThread crashed.  
[2022.02.01-17.26.34:274][756]LogWindows: Error: HandleError re-entered.  
[2022.02.01-17.26.34:274][756]LogWindows: FPlatformMisc::RequestExit(1)  
[2022.02.01-17.26.34:274][756]LogCore: Engine exit requested (reason: Win RequestExit)  
[2022.02.01-17.26.34:497][756]Log file closed, 02/01/22 12:26:34

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_006810ab1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_006810ab1](https://forums.unrealengine.com/u/anonymous_user_006810ab1)\
**Post date:** [February 12, 2022, 2:06am UTC](https://forums.unrealengine.com/t/ue5-getsocketlocation-returning-origin-or-local-position-instead-of-world-position/492059/10 "2022-02-12T02:06:00Z")

</div>

Well I solved it. The issue was the pointer to the skeletal mesh was incorrect. I thought that because the is valid and has socket if statement was working that the skeletal mesh was correct.

Turns out I was getting “this” as skeletal and not the skeletal component itself, but for some reason that is valid and has the socket? very confusing.
