Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Retrieve the specific name of a Prefab mesh as a result of a Raycast

Discussion in 'Scripting' started by eco_bach, Mar 23, 2021.

  1. eco_bach

    eco_bach

    Joined:
    Jul 8, 2013
    Posts:
    1,601
    Hi guys.
    Trying to retrieve the specific name of a Prefab mesh as a result of a Raycast. This would be the same name viewable in the Project directory.
    ie
    PrefabParent
    > childGameObject <this is the name I am trying to retrieve>
    Right now using the following in my Update(). m_Hit.transform.name prints out indecipherable hexadecimal stuff.

    Code (CSharp):
    1. Ray ray = m_MainCamera.ScreenPointToRay(CenterScreenHelper.Instance.GetCenterScreen());
    2.  if (Physics.Raycast(ray, out m_Hit))
    3.   {
    4.    Debug.Log("ASSERT  hit  " + m_Hit.transform.name);
    5.   }
    6.  
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,519
    This seems unlikely... that should return the name of the underlying UnityEngine.Object... usually this is the same as the GameObject itself.

    Do you get any different result if you use
    m_Hit.transform.gameObject.name
    instead?

    EDIT: I just doublechecked but it's no different when returned from a physics hit. Just the plain old name.