Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Reference Resolution and elemenats made at run time.

Discussion in 'UGUI & TextMesh Pro' started by cmcpasserby, Oct 9, 2014.

  1. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    Having some problems with the Reference Resolution component which i got on my Canvas, and objects that are instantiated at run time.

    I have a script that creates my level select buttons at run time and instantiates prefabs of a button to do this, but these seems to be unaffected by the reference resolution.

    Im assuming this happens since the reference res component does its stuff on Awake or Start and cant handle changes during run time. So is there a way to force it to re run?
     
  2. PiMuRho

    PiMuRho

    Joined:
    Jul 11, 2012
    Posts:
    17
    Are you parenting the prefabs to the canvas (or a child of it) after you instantiate them?
     
  3. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    ya they are instantiated, than parented to a panel called LevelSelect which is the child of Canvas.

    The prefab its self is a button with a label its child, and a custom script added to it.
     
    Last edited: Oct 9, 2014
  4. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,870
  5. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    thanks i just needed to use Transform.SetParent(go) as opposed to Transform.Parent = go.

    though if you know need to use SetParent as opposed to the parent flag shouldn't Transform.Parent be marked deprecated just like Transform.Active is?
     
  6. runevision

    runevision

    Joined:
    Nov 28, 2007
    Posts:
    1,870
    Using transform.parent keeps the world position, rotation, and scale. This is by design and has always been that way, it just happens to rarely be what you want for UI related use cases. We don't want to deprecate it though since it's still useful for many other things. We also don't want to make the behavior opposite for RectTransform compared to Transform since that would most likely be even more confusing.
     
  7. cmcpasserby

    cmcpasserby

    Joined:
    Jul 18, 2014
    Posts:
    315
    Ah so for gamebojects in world space i should still use Transform.Parent like i normally do.

    Thanks for the info, been trying to figure out why my dynamic UI elements were mis behaving for a while now, didn't expect it to be something so simple.