Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Instantiating a prefab with SetParent does not move physics colliders from originating transform

Discussion in '2018.2 Beta' started by greengremline, Jul 9, 2018.

  1. greengremline

    greengremline

    Joined:
    Sep 16, 2015
    Posts:
    183
    Appears to have been reported before, but was closed:
    https://issuetracker.unity3d.com/is...pdating-to-match-attached-gameobject-location

    If something with a box collider is instantiated, then SetParent is called with worldPositionStays = false, then the collider will not get moved until you either
    1. Move it in the editor
    2. Enable / disable either the collider or isTrigger
    3. Move the collider
    It will appear to have moved, and the gizmo in the editor is in the correct spot, but collisions / triggers will not get called there but instead where the collider was before SetParent was called
    I have had to add a coroutine to my main trigger component to make the triggers work:

    Code (CSharp):
    1. private IEnumerator<float> _FixTriggers() {
    2.       yield return Timing.WaitForOneFrame;
    3.  
    4.       Vector3 fakePos = gameObject.transform.position;
    5.       fakePos.x += 0.0001f;
    6.       gameObject.transform.position = fakePos;
    7.       fakePos.x -= 0.0001f;
    8.       gameObject.transform.position = fakePos;
    9.     }
    This has happened on 2018.2 betas 6, 7, 8, 9, 10, and the release candidate.
     
    Last edited: Jul 9, 2018
  2. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,136
    Thanks for your report!
    The issue you referenced was closed because QA was not able to reproduce it with the available information. If you found a way to reproduce this consistently I advise you to submit a new bug report for it. Posting on the forum should always be secondary to submitting a bug report. Submitting what you wrote here would be sufficient. If you want to go the extra mile, adding a minimal reproduction project to your report would be a huge help and speed up the resolution process significantly. If you submit a bug report and want to raise awareness of the issue on the forums, please make sure to reference the Issue ID of your report.

    Edit:

    We had a go at it, but weren't able to repro. Your description is missing some info about what the instantiated collider is supposed to be doing before it’s moved.
     
    Last edited: Jul 10, 2018