- Home /
Can the Script Execution order be adjusted for FixedUpdate()?
The reason I am asking this is that I have a Player, a Bow and an arrow. the bow follows the arrow and is placed a distance away from the player in the direction of the mouse and rotated to face the mouse. the arrow is spawned by the bow and is held in place at the bow's location and rotation.
The issue is that when the player moves, this causes the bow to move to the last frame's location of player, the same happens for the arrow... so its like I have rubber banded the three objects together as opposed to gluing them together.
can I update the player location, then bow then arrow in the same frame so they are all in the same location when the frame goes to render?
or am I simply going about this all wrong?
Hi, to solve this kind of dependencies, one solution is to have a "master object", or a "manager object" that just simply call some FixedUpdate-like functions on other objects in the order you want. e.g. during Player's FixedUpdate, call Bow.$$anonymous$$yFixedUpdate then Arrow.$$anonymous$$yFixedUpdate, or any order needed to manage positions dependencies.
Edit: Well, re-reading your question: maybe you want to have the bow child of the player, and the arrow child of the bow, then you don't have to update position as a child will follow the parent's position. If you need to shoot the arrow, you can detach it so it has it's own life in the "World space".
Answer by Zeoli · Mar 29, 2017 at 08:11 AM
I like the answers/suggestions given but in this case I wanted to keep the bow separate. reordering the execution sequence did not work.
I fixed this solution and will state what I did so that others may find this useful.
I ended up rewriting the movement code for the bow and arrow along with the shooting. what I ended up with is that when the player is moved, in the player's fixed update where we move the player, we also call Bow.Move(Vector3 position, Quaternion rotation). this function updates the bow's location and rotation but also calls Arrow.Move(Vector3 position, Quaternion rotation) if the arrow had not been fired.
now, all movement that the bow and arrow do, is actually executed during the fixed update for the player.
Answer by eddyb · Dec 19, 2019 at 10:48 PM
For the record, I'd just like to add here that, yes, the "script execution order" settings also affect FixedUpdate() order, not just Update().
I was looking for the answer to that and saw conflicting answers, and Unity's docs don't explicitly say one way or the other, so I just tested it (in 2019.1) and it works as one would hope.
Answer by AurimasBlazulionis · Mar 28, 2017 at 03:10 PM
If Script Execution Order in the Edit panel does not solve the issue, then the solution is rather simple: update the positions in LateUpdate. Or you just set up the execution order the wrong way. Try both. Would be great to see your execution order tab.
The problem with LateUpdate is that it's part of the Update (frame) cycle, not the FixedUpdate (physics) cycle.