Search Unity

Layout group make Object smaller ...How fix that?

Discussion in '2D' started by shuskry, Oct 14, 2017.

  1. shuskry

    shuskry

    Joined:
    Oct 10, 2015
    Posts:
    462
    Hi everybody ! I want to do a simple Vertical Grid Layout Group for a list of sentence.

    When i am in the editor and i put manually object in the Grid layout group, All is ok !

    But if i'm instanciate this text object in the game , the size of the object become smaller ..

    I had already set the canvas to Screen size but nothing change :/ ...


    If someone can help me i'll really appreciate !:)
    Have a good day !
     
  2. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    After instantiating the game object, set the scale to Vector3.one
    I think it will solve your problem.
     
  3. hlw

    hlw

    Joined:
    Aug 12, 2017
    Posts:
    250
    If what MiladZarrin1 says dosn't fix your problem ,try maybe to add your prefab manually as a child of your vertical layout group. Then, once it has the right size, create a new prefab using this object, instantiate that new prefab instead of the old one.
    Si ce que MiladZarrin1 ne donne pas le résultat escompté, essaye peut-être d'ajouter ton prefab manuellement en child de ton vertial layout group. Une fois qu'il a la bonne taille, recrée un prefab en utilisant l'objet ayant la bonne taille, puis instantiate ce nouveau prefab.

    If that still doesn't work, i believe you need to modify the pivots.
     
  4. shuskry

    shuskry

    Joined:
    Oct 10, 2015
    Posts:
    462
    @hlw Thanks for youre answer, i have already try do this but nithibg change:/

    How can i set the scale like said @MiladZarrin1 ?

    Thanks for youre help !
     
  5. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    For an accurate answer I need your Instantiate Code. But it generally goes like this:

    Code (CSharp):
    1. GameObject g = (GameObject)Instantiate(...);
    2. g.transform.localScale = Vector3.one;
     
  6. shuskry

    shuskry

    Joined:
    Oct 10, 2015
    Posts:
    462
    Okay thanks ! here my instanciate's code! :)

    Code (CSharp):
    1. public  void AddInfoUI(string UIInfo)
    2.     {
    3.           GameObject InfoObject = Instantiate(InfoPrefab);
    4.           InfoObject.transform.SetParent(PanelInfoUI.transform);
    5.           InfoObject.transform.GetChild(0).GetComponent<Text>().text = UIInfo;
    6.     }
     
  7. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    Just add this line at the end of your code:

    Code (CSharp):
    1. InfoObject.transform.localScale = Vector3.one;
    I think it will solve your problem. let me know the result.
     
    yusril19 likes this.
  8. shuskry

    shuskry

    Joined:
    Oct 10, 2015
    Posts:
    462
    Okay thanks ! I will test that tonight and I'll come back to you !
    Thanks for youre help!
     
  9. shuskry

    shuskry

    Joined:
    Oct 10, 2015
    Posts:
    462
    Thanks à lot ! This is work now perfectly !

    Have a good day !:)
     
  10. MiladZarrin1

    MiladZarrin1

    Joined:
    Jul 7, 2013
    Posts:
    78
    You're quite welcome my friend. You have a nice day too :)