Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice


Discussion in 'Prefabs' started by yepp73, Jan 29, 2021.

  1. yepp73


    Jan 2, 2021
    I'm new to unity, but made a object(Man) walking around.
    Then I spread some balls(Bluberry) using this code.

    Code (CSharp):
    1. for (int y=0; y<numBlueberry; ++y)
    2.        {
    3.             GameObject inst = Instantiate(Blueberry, new Vector3(Random.Range(-20.0f, 20.0f), 1, Random.Range(-20.0f, 20.0f)), Quaternion.identity);
    4.    = "Blueberry1";
    5.        }
    Then I try to detect collision.
    Code (CSharp):
    1. private void OnCollisionEnter(Collision collision)
    2.     {
    3.             LogCollsiionEnter.text = "On Collision Enter:" +;
    4.             //Destroy(collision.gameObject);
    5.         }
    6.     }
    The Bluberry1 name is not appearing.
    If the man walk into an other object witch is not a prefab , the name will show.

    If I do the destroy it will work. But I'm not able to sort out by name or tag.

    Also if I don't tick 'is trigger' the man stops when walking into a blueberry.

    I have also tried but same result.

    What is it I'm getting when it comes to Prefabs and collision ?

    I need to be able to sort on collision.

    Thankful for all help.

    Greeting Kaizen.
    Last edited: Jan 29, 2021
  2. yepp73


    Jan 2, 2021
    I found that the problem is the actual name of the prefab. Depending on some the situation (Can not figure out what is causing what) the created gameobject from prefab got a different name. Sometimes the name + (clone).
    Strange behavior...