- Home /
transform.forward breaks when changing scenes
So I managed to get transform.forward to work, but when I build the game and change the scene to the needed one (takes about 3 scene changes) transform.forward starts working like Vector3.forward. In the editor, when starting the game on the needed scene everything is alright. Why is that so?
Edit: More details, as you ask. I have tried modifying a script in the built game using dnSpy some time before that used transform.forward to move the Player. When switching the scene from one to the another needed one transform.forward would also become broken. I don't know any other possible details, besides listing every single object in the scene and every used script possible.
Are you sure you are calling it on an instance and not a prefab reference? Anyway, the transform.forward will return the same value as Vector3.forward if the object's euler angles are (0, 0, 0) in world space.
The script gets the forward of the object it's on (and it works absolutely fine in the editor when starting the game from the scene with the object and the script) and the object is the player that rotates a lot. What did you mean by calling on a prefab instance and an object instance?
Let's say you have a reference like this: public GameObject whatever;
. You can assign a scene object (instance) or an asset in the assets folder (prefab) to this variable. So if you call whatever.transform.forward
, you could be calling this on a prefab.
The script was assigned to the Player gameObject and it couldn't be executed if it was a prefab, also it was working perfectly fine(not in the build), as I said. Sorry, I kinda misunderstood your point
Sorry but your first question was as unspecific as this one. Also your answer on your other question is also pretty pointless. Your conclusion makes no sense. Searching for an object works pretty well as long as you know what you're searching for and as long as there are no ambiguous objects in the scene. In neither question have you included your actual code used or any hint what objects are involved or how your hierarchy looks like.
If you're expecting any answers from us you have to include way more details in your question. Usually we would just close questions like that since it can't be answered as it's too unspecific.
So please edit your question and add more details.
Gee. Should I give a link to a 6+ GB project? There is not much of a script, just simply getting the transform.forward. I could include anything that would be related to the issue if I knew what could be. And the answer for my previous question has helped me and everything worked fine(except for this scene thing) after that. I also could and may be asking for any possible reasons and causes, that I could have missed.
Answer by GreatCorn · Aug 09, 2018 at 07:36 AM
Turns out I have better luck talking to a wall than getting any possible answers, ideas or solutions. As always figuring everything by myself. Getting the transform.forward in LateUpdate() fixed the error for me, as I also additionally called LateUpdate() manually from Start() and Awake(). Thanks for some attention, at least, that's rare..