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

Showcase InvokeRepeating

Discussion in 'Prefabs' started by combra, Nov 10, 2022.

  1. combra

    combra

    Joined:
    Nov 27, 2019
    Posts:
    13
    Hi, I have a question when I use invokerepeating, when it runs, the prefab created is outside the hierarchy, what I want is for all prefabs to be invoked within a specific GameObjects. In the image cube is outside and I would like to put it inside any object father, son...
     

    Attached Files:

    • c2.png
      c2.png
      File size:
      6.9 KB
      Views:
      92
  2. MirceaI

    MirceaI

    Unity Technologies

    Joined:
    Nov 24, 2020
    Posts:
    35
    Hi @combra! Can you please post the code you are using or a simple sample project?
     
  3. combra

    combra

    Joined:
    Nov 27, 2019
    Posts:
    13
    With this code that I'm using, it calls prefabs, at controlled random coordinates, but like I say, I want it to call prefabs inside specific GameObjects, then use the random coordinates of that GameObject.
     

    Attached Files:

  4. combra

    combra

    Joined:
    Nov 27, 2019
    Posts:
    13
    Let me explain myself better, I want every invoked with InvokeRepeating object to be a child of another object
     
  5. MirceaI

    MirceaI

    Unity Technologies

    Joined:
    Nov 24, 2020
    Posts:
    35
    From your code it seems you are using
    Code (CSharp):
    1. public static Object Instantiate(Object original, Vector3 position, Quaternion rotation);
    to instantiate your objects. On the documentation page of Instantiate you can find more overloads of this function, some of which accept the parent as parameter.

    Alternatively you can set the parent of your object later using something like:
    Code (CSharp):
    1. var myObject = Instantiate(...) as GameObject;
    2. myObject.transform.parent = parent