- Home /
transform.forward not updating?
OK, this is patently weird (to me, anyway)
So I've been trying to get the degree on a single local axis between two points for a while now, and that, in and of itself works fine. However, I also need to compare this angle to another angle, and now I've noticed something odd: As far as I understood, the transform.forward parameter should always hold the global direction the object is facing, however, for me it only seems to update if I manually assign the forward Vector in a script (It also correctly displays the changed, new rotation in the editor and game view). If I simply change the rotation either from within a script or by using the direct editor controls, the forward Vector's value doesn't update. This is true both for main GOs as well as their individual children.
I thought that transform.forward was effectively identical with transform.TransformDirection(Vector.forward) (Which doesn't do anything for me either), is this incorrect?
BTW, I'm using the most current version of Unity (Non-Pro)
Any help will be greatly appreciated.
I don't have an answer, other than to say I think it's pretty unlikely that there's a bug in the Transform.forward property. As such, my guess would be that the problem is elsewhere (e.g. you're not querying the data from the right game object, or are querying the data at the wrong time, or something of that sort).
Well, I found it unlikely too, but here's what I used to test different objects (Without any other scripts attached):
using UnityEngine; using System.Collections;
public class DirectionTestScript : $$anonymous$$onoBehaviour {
// Update is called once per frame
void Update () {
Debug.Log("direction: " + transform.forward );
}
}
result: 0,0,-1 stopping the game, changing the rotation in the editor window by 180 degrees: 0,0,-1 rotating the object at runtim in the editor window randomly: 0,0,-1
I don't know what's wrong, the rotation is actually correctly displayed in game.
Edit: Tried the other rotations via editor too, btw...
Do you have 'collapse' turned on in the console by any chance? (I'm not sure if that would have any bearing here, but it's often mentioned when people aren't getting the debug output they expect :)
Jesse: Nope, only clear on play is toggled
Ben: Same problem, it's showing me -1,0,0
Answer by Peter G · Jun 04, 2011 at 01:57 AM
I have never had any problems with transform.forward
. Not to say that you haven't discovered a bug, but I'm skeptical. How are you checking the value of transform.forward
? There are lots of ways that you can test the values of it, the easiest would just be to
Debug.Log(transform.forward);
in an Update()
and see what you get.
Answer by andrew_johnson_cubic · Sep 15, 2016 at 01:34 PM
I think I had the exact same issue. It started after I crashed the editor.
Toggling enable on the affected script in the editor during run-time would make transform.forward report the correct value again.
I solved my problem by copying the whole script (Ctrl-A so I didn't miss anything) into a new file with a different name.
Conjecture Warning --> Does Unity have meta-data of script files? That might explain it.
(I know I'm 5 years late, this is for any future forum miners and time travellers that have this issue)
$$anonymous$$an you saved me, I've been banging my head against the wall for the past couple of hours. It appears that unity can corrupt this relatively easily.
Your answer
![](https://koobas.hobune.stream/wayback/20220612095101im_/https://answers.unity.com/themes/thub/images/avi.jpg)