Search Unity

Rigidbody2D has an invalid movement state index during remova (Unity 2019.1.0)

Discussion in 'Physics' started by massiveminiteam, May 8, 2019.

  1. massiveminiteam

    massiveminiteam

    Joined:
    Aug 28, 2018
    Posts:
    109
    Hi,

    we are receiving the error "Rigidbody2D has an invalid movement state index during removal" while playing in the editor.

    Has someone else the same problem and maybe a fix for it?

    Thanks
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    First time I've seen that reported. It would be good if you could submit a bug report with a simple reproduction case so it can be looked at.
     
  3. Ziya

    Ziya

    Joined:
    Aug 30, 2013
    Posts:
    65
    First time I've seen that happened to me.
    It happened right after my first update from Unity 2018.3.8f1 (64-bit) to Unity 2019.1.9f1 (64-bit).

    I do have multiple components of Rigidbody2D set to:
    Body Type - Static
    Simulated - Checked
    Sleep State - Asleep

    It happens when I destroy gameObjects with Rigidbody2D.
     
    Last edited: Jul 10, 2019
    unity_bAkIbHiWQE71zA likes this.
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Unfortunately we've not seen a single bug report on this either.
     
  5. Romain-Macre

    Romain-Macre

    Joined:
    Dec 26, 2015
    Posts:
    8
    This bug happens for me in that scenario:
    - First, a RigidBody2D has its interpolation changed BY CODE, from RigidbodyInterpolation2D.Interpolate to RigidbodyInterpolation2D.None.
    - Then: Changing the scene (the RigidBody2D gets destroyed)

    Note: it looks like it doesn't matter which way the RigidbodyInterpolation2D is changed by code (from None to Interpolate, or the other way around). It then triggers the error about 30% of the time when restarting the scene.
     
    Last edited: Aug 2, 2019
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    I cannot duplicate this so would you mind creating a bug report and posting the case number so I can look at it? Either that or upload a test project here with reproduction instructions.

    I cannot fix what I cannot reproduce and there's been no bug reports so far.
     
    Last edited: Aug 2, 2019
  7. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
  8. Romain-Macre

    Romain-Macre

    Joined:
    Dec 26, 2015
    Posts:
    8
    I'm on 2019.1.7. Very weird, because that bug report says that 'Interpolation does not work when it is set during runtime', but for me it does work (apart from that error that is) and my version is older than the fixed version.
    I'll create a bug report. Thanks.
     
  9. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    That's because the bug report titles submitted are often terrible descriptions of the actual issue.

    If you provide the case number I can take a look at it otherwise I might not see it for a fair while.
     
    Last edited: Aug 2, 2019
  10. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    I just wanted to stop by again and reiterate that I've yet to see a bug report.
     
  11. j1mmie

    j1mmie

    Joined:
    Oct 31, 2013
    Posts:
    31
    Also seeing this after changing a Rigidbody2d's Interpolate mode to "Interpolate". Using Unity 2019.2.6f1

    https://i.imgur.com/YW14NgS.png

    Note that I've made this change in the EDITOR. Not changing programmatically at runtime.

    Will submit a bug report.
     
  12. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Could you please try 2019.3 to see if the issue persists there. It might be that the previously fixed bug above needs backporting.
     
  13. listop80

    listop80

    Joined:
    Dec 25, 2019
    Posts:
    1
    This is happening to me too in unity 2019.3.0f3. Im not changing interpolation, but destroying some gameobjects that contain rigidbody2d
     
  14. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Unfortunately I've not seen a single bug report on this. If you have a method to reproduce it then I would kindly ask that you submit it, preferably with a simple reproduction project attached.
     
    Last edited: Dec 28, 2019
  15. Deleted User

    Deleted User

    Guest

    Same bug happened. I can reproduce everytime :

    1) I have a player with :
    a) RigidBody2D with body type set to Dynamic
    b) detection mode set to continuous
    c) interpolate set to interpolate
    2) Destroying the object like that does not ause any problem
    3) If is set the body type (by script) to static, i get the problem everytime
    4) Changing the body type to kinematic does not cause the problem
    5) Even if the player is not moving, i get the problem.
    6) I did try to change the velocity to zero with static body type... same problem

    After some tests :
    I destroy my player inside a coroutine. After removing extra codes in my coroutine, this cause the bug :
    public IEnumator CoDestyoyMe()
    {
    thisRigidBody.bodyType = RigidbodyType2D.Static;
    yield return new WaitForSeconds(1f);
    Destroy(gameObject);
    }
    If i remove the WaitForSeconds, everything is good (no bug).
     
    Last edited by a moderator: Feb 2, 2020
  16. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Would you mind submitting this reproduction case as a bug report and sending me the case number so I can look at it? I'll try your reproduction steps though.

    This would be the first bug report since it was first mentioned above last March and would like to see and fix it.
     
    Last edited: Feb 2, 2020
  17. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    On 2019.2.19f1 & 2019.3.0f6 I followed your reproduction instructions above using the following script and GameObject set-up but couldn't duplicate it unfortunately:

    https://gyazo.com/0f44af0deb1fe1e85950b5e123ec3888

    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3.  
    4. public class TestScript : MonoBehaviour
    5. {
    6.     private Rigidbody2D m_Rigidbody;
    7.  
    8.     void Start()
    9.     {
    10.         m_Rigidbody = GetComponent<Rigidbody2D>();
    11.     }
    12.  
    13.     void OnGUI()
    14.     {
    15.         if (GUI.Button(new Rect(new Vector2(100f, 100f), new Vector2(250f, 200f)), "DoIt!"))
    16.         {
    17.             StartCoroutine(DestroyBody());
    18.         }
    19.     }
    20.  
    21.     IEnumerator DestroyBody()
    22.     {
    23.         m_Rigidbody.bodyType = RigidbodyType2D.Static;
    24.         yield return new WaitForSeconds(1f);
    25.         Destroy(gameObject);
    26.     }
    27. }
     
    Last edited: Feb 2, 2020
  18. Deleted User

    Deleted User

    Guest

    I submited the bug (Case 1216772) and attached a project (.7z file). If you run it as is, you will trigger the bug. I strongly suggest that you look at the way to NOT trigger the bug... it's weird.

    For other reading this, this bug is so strange that i don't know what is the cause of it. In the project is submited i sometime change the body type from static to kinematic (because i don't want my object to move) in order to solve the problem. I can also just remove a "yield return new WaitForSeconds(1f)" or remove a "RigidBody2d" on an object that is never destroyed and ... miracle... the bug disapear... it' not logical at all... I cannot help more.
     
  19. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Thank you very much!

    I'll look at it this week as soon as I get a chance.
     
  20. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    I just want to say thank you as today I managed to duplicate the issue. This is the first time I've had a bug report on this despite asking several times so I'll go ahead and find the source of the issue.

    Thanks again.
     
  21. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    I've fixed the issue.

    The issue is caused by changing to a static body but not adding/removing or generally changing the scene in a way that causes movement-state to be rebuilt. Unfortunately when changing to static, no movement state is required and should be reset. The delay simlpy means than when you destroy the object, the deferred delete tries to remove it from the movement state system and it's invalid.

    Not changing to Static would stop this or deleting it instantly.

    Anyway, I'll process the fix and a backport.
     
  22. midsummer

    midsummer

    Joined:
    Jan 12, 2017
    Posts:
    38
    I ran into this issue recently also. I think I tried to disable a 2D spring joint by making one of the Rigidbody2Ds static in a script. Apparently disabling joints isn't quite that easy, and attempting this made the "invalid movement state index" error message appear as a weird side effect. It was difficult to find the culprit, because the error didn't appear until exiting playmode, seemingly at random. I think this error also caused my builds (macOS) to crash on quit sporadically.

    I ended up doing things a bit differently in my project to avoid the error, but it's nice to see that this issue has since been recognized and a fix is coming.
     
  23. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Yes, it's a shame my repeated asking for bug reports since the original post didn't result in a report. Thankfully cbonneville did a great job and produced a bug report that could consistently reproduce it and it was an easy fix.

    It's being reviewed now and will be backported when that's done. It'll land in a set of three bug fixes together so you can keep an eye out for any of them:
    1. https://issuetracker.unity3d.com/is...n-invalid-movement-state-index-during-removal
    2. https://issuetracker.unity3d.com/is...-rigidbody2d-when-child-is-set-to-interpolate
    3. https://issuetracker.unity3d.com/issues/ontriggerexit2d-when-disabling-a-gameobject
     
  24. Ed-Den-Gaming

    Ed-Den-Gaming

    Joined:
    May 26, 2020
    Posts:
    9
    Hey MelvMay

    Has this update been made available? I'm using Unity 2019.21f1

    Thanks
     
  25. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    I took at a look at that and it was fixed in 2020.1 and 2019.3 but was unfortunately rejected for 2019.2 for various reasons (mostly risk) during review (not all fixes landed in backports). If you're experiencing this issue then I can understand this might not be what you want to hear if you cannot or don't want to move to 2019.3, especially due to a single issue.

    It is possible this could be reviewed again and sometimes when a change/fix lands can affect the decision.
     
  26. Ed-Den-Gaming

    Ed-Den-Gaming

    Joined:
    May 26, 2020
    Posts:
    9
    Cool. I'm updating now anyway. Might as well as I am having an issue with GetComponent() as it wont show up in the inspector as registered. Hopefully the update will solve that.