Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Shine_Bolt · Jun 01, 2019 at 02:46 AM · timescaletimestep

Unity Events executed out of order

According to this page Events in unity are suppose to execute in a specific order. Specifically, OnCollisionEnter is supposed to be called right after all of the OnTriggerEnter functions have been called on all objects; however, FixedUpdate and Update are both being called at least once in between calls to my OnTriggerEnter2D and OnCollisionEnter2D functions in my Enemy class.

Here is my code:

 public class Enemy : Combatant
 {
     public int kill_points;
     public float force;
     public List<GameObject> path_verticies;
     private int pathi;
     private bool on_path;
     private bool is_flying;
     private bool ignore_collision;            //Used for ignoring collisions with walls, if the enemy has already touched an enemy_controller.
     void Start ()
     {    Init();
         pathi = 0;
         ignore_collision = false;
         is_flying = false;
         if (gameObject.tag.Contains("Fly")) is_flying = true;//Assuming contains is cheaper than a full string compare.
         on_path = null != path_verticies && 0 != path_verticies.Count;
     }
 
     private void FixedUpdate() { ignore_collision = false; }
 
     void Update ()
     {    if (!CheckBounds()) Destroy(gameObject);
         if (on_path)
         {    transform.LookAt(path_verticies[pathi].transform, Vector3.up);
             transform.Rotate(new Vector3(0,-90,0));
             phys.velocity = transform.right * speed;
         }
         else dx = Mathf.Sign(Cx) * speed;
     }
 
     public void Flip(){ Cx *= -1; }
 
 #pragma warning disable CS0642 // Possible mistaken empty statement
     private IEnumerator OnCollisionEnter2D(Collision2D collision)
     {    if (on_path && path_verticies[pathi] == collision.gameObject)
         {    if (collision.gameObject == player)
             {    throw new System.NotImplementedException();
                 yield return new WaitForSeconds(0.1f);//Used to prevent damage to the player if the player landed on top of the enemy.
                 var atk = player.GetComponent<Combatant>().vigor.Attack(2);
                 if (Health.Atk.DIES == atk) player.GetComponent<Life>().Die();
             } else pathi = (pathi+1) % path_verticies.Count;
             yield return new WaitForSeconds(0.0f);
         }
         else if (on_path)
         {    if (collision.gameObject == player)
             {    yield return new WaitForSeconds(0.1f);//Used to prevent damage to the player if the player landed on top of the enemy.
                 var atk = player.GetComponent<Combatant>().vigor.Attack(2);
                 if (Health.Atk.DIES == atk) player.GetComponent<Life>().Die();
             } else if (collision.collider == On(Truebounds)) /*nothing*/;
             else if (collision.gameObject.layer == 0 || collision.gameObject.layer == 8)// TODO
                 /*take velocity in the direction opposite of the normal and add it to
                  * the perpendicular component the enemy is moving in*/;
             yield return new WaitForSeconds(0.0f);
         }
         else
         {    if (collision.gameObject == player)
             {    yield return new WaitForSeconds(0.1f);//Used to prevent damage to the player if the player landed on top of the enemy.
                 var atk = player.GetComponent<Combatant>().vigor.Attack(2);
                 if (Health.Atk.DIES == atk) player.GetComponent<Life>().Die();
             } else if (ignore_collision) /*nothing*/;
             else if (collision.collider == On(Truebounds)) { if (is_flying) Flip(); }
             else if (collision.gameObject.layer == 0 || collision.gameObject.layer == 8) Flip();
             yield return new WaitForSeconds(0.0f);
         }
     }
 
     private IEnumerator OnTriggerEnter2D(Collider2D collider)
     {    var component = collider.GetComponent<MonoBehaviour2>();
         if(!component) yield return null;
         else if (on_path && path_verticies[pathi] == collider.gameObject)
             pathi = (pathi+1) % path_verticies.Count;
         else if (on_path) /*nothing*/;
         else if (component.type == typeof(Enemy_Controller)) { Flip(); ignore_collision = true; }
         yield return null;
     }
 #pragma warning restore CS0642 // Possible mistaken empty statement
 
     //public void OnDestroy(){  }
 }


And these are my timestep settings: alt text

temp.png (6.6 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

105 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't reproduce some physics sequence 1 Answer

Altering Fixed Timestep when your game is running to allow for smooth low Timescale animation. 2 Answers

Is it possible to tick the fixed timestep manually or increase the timescale beyond 100? 2 Answers

Javascript Timescale Problem 0 Answers

Can i ignore timescale when playing AudioSource.PlayClipAtPoint ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges