Search Unity

Instantiated PreFab with TextMesh Pro is not showing

Discussion in 'Prefabs' started by allpublic, Jun 16, 2021.

  1. allpublic

    allpublic

    Joined:
    Nov 10, 2020
    Posts:
    13
    Hey guys,

    I found a behavior that I don't understand.
    I have a GameObject with some child GameObjects. Like SpriteRenderer and TextMesh Pro. If I use this as PreFab and just put in the scene it works well. The text ist visible and it works as expected.

    If I Instantiate this PreFab as a new clone, the text is not visible. It's visible in scene but is not rendered in game.

    What I tryed to figure:
    - I compared the GameObjects but couldn't find any difference.
    - I upgraded from 2021.1.5f1 to 2021.1.11f1
    - Tryed to rebuild the setup in a new project but couldn't recreate the issue yet. I didnt add all functions yet.

    Here is the script for instantiating:

    Code (CSharp):
    1. GameObject mushroomObject = Instantiate(mushroomPreFab);
    2.                 mushroomObject.GetComponentInParent<Transform>().localScale = new UnityEngine.Vector3((votedStatement.age + 1f) / 5f, (votedStatement.age + 1f) / 5f, 0f);
    3.                 mushroomObject.GetComponentInParent<MushroomBaseScript>().setPosition(new UnityEngine.Vector3(x, y, z));
    4.  
    Anyone has an idea? Bildschirmfoto 2021-06-16 um 22.17.30.jpg
     
  2. allpublic

    allpublic

    Joined:
    Nov 10, 2020
    Posts:
    13
    I figured it out:

    Code (CSharp):
    1. mushroomObject.GetComponentInParent<Transform>().localScale = new UnityEngine.Vector3((votedStatement.age + 1f) / 5f, (votedStatement.age + 1f) / 5f, 1f);
    I setted 0f for z axis. Because TextMesh Pro is a 3D object is also need a depth. So it has to be > 0f for z axis.
     
  3. adrianwong135

    adrianwong135

    Joined:
    Feb 14, 2022
    Posts:
    1
    for the gameobject with the TMPro attached, does it have a parent class with a canvas component when instantiated?
     
    Niter88 likes this.
  4. maochemike

    maochemike

    Joined:
    Nov 24, 2021
    Posts:
    1
    it didn't work for me , I have the same issue and I did increase my z-axis to 1.
     
  5. Niter88

    Niter88

    Joined:
    Jul 24, 2019
    Posts:
    112
    The text needs to be inside a gameobject with a canvas component, it also needs to be positioned inside the canvas.

    Try to do a prefab of a canvas containing the text instead