ShaneS429

  • 11 سبتمبر 2015
  • انضمّ(ت) 30 يوليو 2015

    Could this be a problem with script execution order in Unity?

    I had an issue where I was trying to rotate a bone to aim towards a touch location and then proceed to fire a weapon. By default, scripts are loaded at random and then executed in said random order. In my case, an issue would arise where the skeleton update would get called before my input event that triggered a bone rotation and weapon fire.

    Even though in my code it went something like:

    shoulderBone.transform.localRotation = aimRotation;
    equippedWeapon.Fire();

    Because skeleton update was called first, what really happened was the above code would execute on frame 12 for example, and the skeleton wouldn't update until frame 13 since it's update was already called in frame 12 before I told it to change any rotations.

    Perhaps something like this is happening to you? The attachments are updating, but then your event that triggers an attachment change is happening after they already updated for that frame. Perhaps try to use the Script Execution Order and have your input events happen before default time so that way they occur before the skeleton updates.

    This at least fixed my issued to get the skeleton to update after I did any runtime modifications. Hopefully it's a similar issue for you.

    So I just purchased the Gunman pack a day or two ago to mess with in Unity. I was just really curious how things like animation combining, aiming, and overall character controlling was done in this.

    Before I proceeded with my project, I loaded up the asset pack scene, and attempted to duplicate the Gunman a number of time just to see how performance was on mobile. I modified the touch script so that all the characters would shoot at the same touch point.

    I was getting a weird bug where sometimes the gunman would perform perfectly. I'd touch the screen, the arms would rotate, a shot would be fired towards the touch point. Although, seemingly randomly, some of the duplicated gunman wouldn't follow that logic. Instead, they would, shoot, then rotate to point their weapons at the touch point. I spent all day trying to figure out why sometimes they'd fire perfectly, and other times they would seem to fire before rotating their arms.

    It turns out that simply highlighting the Gunman object and duplicating said Gunman would cause any of the duplicate gunman to potentially misbehave. However, if I dragged in any number of prefab gunman from my Assets folder, they would all behave absolutely perfectly. I'm not sure if this has something to do with Unity or some sort of sync issue with the gameobjects and Spine skeleton data or what.

    Any thoughts? I don't foresee this every being a problem. Just curious if there was an explanation.


    Strike that. I'm handling player states in a different way then the example, and I guess my code is somehow triggering the Fire( ) call before AimPivot completes it rotation.