# 'Actor Position WS', but I need Actor Rotation WS

**URL:** <https://forums.unrealengine.com/t/actor-position-ws-but-i-need-actor-rotation-ws/363535>\
**Category:** Rendering\
**Tags:** unreal-engine, question\
**Created:** [July 10, 2016, 11:42am UTC](https://forums.unrealengine.com/t/actor-position-ws-but-i-need-actor-rotation-ws/363535 "2016-07-10T11:42:49Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_87a763d9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_87a763d9](https://forums.unrealengine.com/u/anonymous_user_87a763d9)\
**Post date:** [July 10, 2016, 11:42am UTC](https://forums.unrealengine.com/t/actor-position-ws-but-i-need-actor-rotation-ws/363535/1 "2016-07-10T11:42:49Z")

</div>

Hi, I am creating an imposter UV NPC. I want it to to face the direction of the Rotation XYZ.  
How can I get the Actor/Object Rotation WS in a material blueprint?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_87a763d9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_87a763d9](https://forums.unrealengine.com/u/anonymous_user_87a763d9)\
**Post date:** [July 11, 2016, 6:08pm UTC](https://forums.unrealengine.com/t/actor-position-ws-but-i-need-actor-rotation-ws/363535/2 "2016-07-11T18:08:18Z")

</div>

bumpbump12

---

<div class="post-metadata">

**Author:** ![Oskar\_Swierad](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/oskar_swierad/32/465778_2.png) [@Oskar\_Swierad](https://forums.unrealengine.com/u/Oskar_Swierad)\
**Post date:** [July 12, 2016, 4:55pm UTC](https://forums.unrealengine.com/t/actor-position-ws-but-i-need-actor-rotation-ws/363535/3 "2016-07-12T16:55:44Z")

</div>

This will give you the local Z direction.

> **[Coordinates Expressions](https://docs.unrealengine.com/4.27/en-US/RenderingAndGraphics/Materials/ExpressionReference/Coordinates/)**
>
> Expressions that perform actions on texture coordinates or output values that can be used as, or to modify, texture coordinates.

[https://docs.unrealengine.com/latest/images/Engine/Rendering/Materials/ExpressionReference/Vector/ObjectOrientationExample.jpg](https://docs.unrealengine.com/latest/images/Engine/Rendering/Materials/ExpressionReference/Vector/ObjectOrientationExample.jpg)

But maybe you need a simpler setup:

- getting the Z-axis rotation in a blueprint
- writing it there to a Material Parameter Collection (it’s a global variable container from which materials can read)
- then using an ImposterUV node in the material?

Oskar

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_87a763d9](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_87a763d9](https://forums.unrealengine.com/u/anonymous_user_87a763d9)\
**Post date:** [July 15, 2016, 8:31pm UTC](https://forums.unrealengine.com/t/actor-position-ws-but-i-need-actor-rotation-ws/363535/4 "2016-07-15T20:31:52Z")

</div>

To cut to the case I am creating an ARK mod. I’ve replaced the character 's skeletal mesh with a plane which rotates towards the player in order to display the 2D texture correctly. So the solution I was seeking wouldn’t have worked.

The best I can think of right now is determining the angle from two points, but I would need to store a previous Actor Position in order to calculate the angle between the two points. Is there a way to store variables in a material?

---

<div class="post-metadata">

**Author:** ![Slavq](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Slavq](https://forums.unrealengine.com/u/Slavq)\
**Post date:** [August 8, 2022, 10:07am UTC](https://forums.unrealengine.com/t/actor-position-ws-but-i-need-actor-rotation-ws/363535/5 "2022-08-08T10:07:40Z")

</div>

It looks like the ActorPosition gives us the location of the whole actor, while ObjectPosition is for individual objects. For example, to visualize, the sphere is attached to the cube here:

 ![parentLocInMaterials](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/9/5/e95d5c2c994a0aa9278ebcc4e27a220e6a2fbcab.jpeg)

Is it possible to get actor orientation/rotation in a similar way that the ActorPosition gives us the position of the parent component? So in this case, on the sphere it would return the orientation of the cube, because the sphere is attached to it.

… Maybe via HLSL…? I’d be grateful for any pointers, if this is possible at all.

---

<div class="post-metadata">

**Author:** ![neofuturelabs](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/neofuturelabs/32/1194562_2.png) [@neofuturelabs](https://forums.unrealengine.com/u/neofuturelabs)\
**Post date:** [October 6, 2022, 3:10pm UTC](https://forums.unrealengine.com/t/actor-position-ws-but-i-need-actor-rotation-ws/363535/6 "2022-10-06T15:10:39Z")

</div>

I found the solution on this Japanese blog post:

> **[【UE4】ObjectのRotationをMaterialから取得する方法 【★★☆】 | キンアジのブログ](https://kinnaji.com/2019/08/19/getanglefrommaterial/)**

Add a custom node with these contents to retrieve a Float3 containing the object’s rotation in radians (recommend making this a material function):

```auto
float3x3 WtoL = LWCToFloat(GetPrimitiveData(Parameters.PrimitiveId).WorldToLocal);
float3 R = float3(
atan2(WtoL[2].y,WtoL[2].z) * -1.0,
asin(WtoL[2].x),
atan2(WtoL[1].x,WtoL[0].x)
);
return R < 0 ? 2 * pi - abs(R) : R;

```

In this case, pi is an argument to the custom node.  
To convert to degrees, multiply the result by 57.2958.

Note that if you want to use this in the “RotateAboutAxis” material node, Component Mask out the degrees value of, for example, B (yaw), divide by 360 (RotateAboutAxis uses a 0-1 scale for rotation), and input it into RotationAngle. Add the result of the RotationAngle node to the initial vector that you’re rotating in order to acquire the final rotated vector.

---

<div class="post-metadata">

**Author:** ![Killerzwerg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Killerzwerg](https://forums.unrealengine.com/u/Killerzwerg)\
**Post date:** [April 28, 2023, 1:52pm UTC](https://forums.unrealengine.com/t/actor-position-ws-but-i-need-actor-rotation-ws/363535/7 "2023-04-28T13:52:18Z")

</div>

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/0/0/7008bdff1f50ff712fe335e36f5ca633aa966fc3.png)

---

<div class="post-metadata">

**Author:** ![neofuturelabs](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/neofuturelabs/32/1194562_2.png) [@neofuturelabs](https://forums.unrealengine.com/u/neofuturelabs)\
**Post date:** [April 28, 2023, 5:33pm UTC](https://forums.unrealengine.com/t/actor-position-ws-but-i-need-actor-rotation-ws/363535/8 "2023-04-28T17:33:04Z")

</div>

Weird that it’s showing that syntax error. You put the code directly into a Custom node in the Material Editor right? I’m on UE5.1.1 and it’s still working for me.

It also seemed to work for the guy in the other post about this:

> [@Get Actor x, y, z rotation angle in shader](https://forums.unrealengine.com/t/get-actor-x-y-z-rotation-angle-in-shader/155362/7):
>
> [mpxc](https://forums.unrealengine.com/u/mpxc) this piece of code helped me a lot, thanks! However, the Y value was wrong so I modified code to work properly (UE5.1.1) float3x3 WtoL = LWCToFloat(GetPrimitiveData(Parameters.PrimitiveId).WorldToLocal); float3 R = float3( atan2(WtoL[2].y,WtoL[2].z) \* -1.0, atan2(WtoL[2].x,WtoL[2].z), atan2(WtoL[1].x,WtoL[0].x) ); return R \< 0 ? 2 \* pi - abs(R) : R;

Note that there is an issue with the Y value calculation in my original post which he mostly resolved in the above post, although it still doesn’t seem to be perfect.
