Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by MorsVitae · Apr 05, 2016 at 05:37 AM · gameobjectprefabinstantiate prefab

How to instantiate a empty gameobject prefab

Hi, I am trying to build a brick breaker game and am trying to create a few empty game objects for the bricks to grab transforms from. So far I have this.

 public GameObject Row1;
 public GameObject Row2;
 public GameObject Row3;
 public GameObject Row4;
 public GameObject Row5;
 void start()
 {
     level = 0;
     spawn ();
 }
 void spawn()
 {
     Instantiate(Row1,transform.position,Quaternion.identity);
     Instantiate(Row2,transform.position,Quaternion.identity);
     Instantiate(Row3,transform.position,Quaternion.identity);
     Instantiate(Row4,transform.position,Quaternion.identity);
     Instantiate(Row5,transform.position,Quaternion.identity);
 }    

I am not getting any errors, but it just isnt working. I have added the prefabs to the variable section of the script and the script is attacthed to an empty game controller object. Any help works, thank you.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
8
Best Answer

Answer by Guhanesh · Apr 05, 2016 at 06:03 AM

There is a typo error in your script. It is void Start() not void start().Check if the spawn() function is getting called by printing something inside the function.Other than this your code should work fine.

If you want to Instantiate a empty gameobject like your question says then here is the code.

      GameObject Row1;
 // Use this for initialization
 void Start () {
             Row1=new GameObject();
             spawn ();
 }
 
 
     void spawn()
     {
             Instantiate(Row1,transform.position,Quaternion.identity);
     }
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MorsVitae · Apr 05, 2016 at 06:21 AM 0
Share

@Guhanesh Yeah after 15$$anonymous$$ of staring at it I found that out. Still new to c# and unity, but thank you for the help.

avatar image Guhanesh MorsVitae · Apr 07, 2016 at 06:42 AM 0
Share

if my answer was helpful, you could mark it as correct or upvote it.(just for the karma :))

avatar image MorsVitae Guhanesh · Apr 11, 2016 at 05:49 PM 0
Share

Sorry for the late response. Had a problem where it wouldn't let me fully sign in.

avatar image TimGS · Jan 27, 2018 at 02:58 PM 6
Share

Beware that in latest Unity (2017) the behavior of this code is different!

The above code snippet will create TWO gameobjects.

The consctructor new GameObject() instantiates gameobject by itself. Instantiate(Row1) will create a copy of gameobject Row1.

avatar image Ishidres TimGS · Jun 11, 2020 at 05:08 PM 0
Share

Thanks for mentioning it. Was pretty confused when Instantiate(new GameObject, ...); caused two objects two spawn.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Object Not Instantiating After Being Destroyed 0 Answers

Why is it important to create an empty gameobject for my prefabs? 0 Answers

What does "Couldn't find matching instance in prefab" mean? 2 Answers

How to get a referance to an instantiated prefab clone ? 1 Answer

Positions of Objects in Unity - World Position, Transform Position, Inspector Position, Local Position, Prefab Positions, Center of Objects for Parents & Childs 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges