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 /
  • Help Room /
avatar image
0
Question by Squishyaura · Aug 28, 2016 at 10:47 AM · instantiateclone

Instantiate without creating clone

Hello, I would like create and spawn a GameObject directly from my code to the scene. I read that if I wanted to do that, I should use Instantiate(). My issue with this though is that it's creating a clone, which I don't need. I simply want to spawn the original GameObject into the scene.

 void createFairy()
     {
         if (Input.GetKey(KeyCode.F))
         {
             GameObject objectToCreate = swap.getPlayables();
             objectToCreate = Instantiate(new GameObject("Fairy"));
             objectToCreate.tag = "Playables";
             //Instantiate(objectToCreate);
         }
     }

This is what I get when I press the F button: alt text

Thanks in advance for the help!

da975ae0cefedf8f79e6621bb95f421f.png (1.1 kB)
Comment
Add comment · Show 5
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 Dream_in_code · Aug 28, 2016 at 12:00 PM 0
Share

if(gameObject.name == "fairy(Clone)"){ Destroy(gameObject);

avatar image Dream_in_code · Aug 28, 2016 at 12:07 PM 1
Share

. You can use if (Input.Get$$anonymous$$ey($$anonymous$$eyCode.F))

{ Instantiate(Gameobject,transform.position.transform.rotation); }

avatar image Squishyaura Dream_in_code · Aug 28, 2016 at 02:07 PM 0
Share

That worked perfectly, cheers!

avatar image NoseKills Squishyaura · Aug 29, 2016 at 03:47 PM 0
Share

I think you should fix the actual problem of creating 2 objects ins$$anonymous$$d of just removing the extra copy. Look at @DiegoSLTS answer @Squishyaura

Show more comments

2 Replies

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

Answer by DiegoSLTS · Aug 28, 2016 at 05:09 PM

"new GameObject()" already instantiates the GameObject in the scene, and Instantiate makes a copy of whatever you pass to it. You have the Fairy and the clone because you're telling Unity to create the Fairy (with new GameObject("Fairy");) and then make a copy of it (with Instantiate).

Just remove the "Instantiate":

 void createFairy()
 {
     if (Input.GetKey(KeyCode.F))
     {
         GameObject fairy = new GameObject("Fairy");
         fairy.tag = "Playables";
     }
 }
Comment
Add comment · Show 3 · 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 Squishyaura · Aug 29, 2016 at 03:57 PM 0
Share

Thank you!

avatar image Wolvorine_911 · Feb 25, 2019 at 09:39 AM 0
Share

Need Help! using this method creates a object in scene but its an empty object with transform component not the prefab that i want to create!

avatar image DiegoSLTS Wolvorine_911 · Feb 25, 2019 at 11:23 AM 0
Share

This question was about creating an empty GameObject, what you're trying to do is different. Just use Instantiate and pass the prefab reference as the first argument.

avatar image
0

Answer by ReggieBeRetro · Aug 29, 2016 at 10:06 PM

or change the name after it is instantiated.

                 objectToCreate.name = "NewFariy_Obj" + spawned;


                 spawned++;
Comment
Add comment · 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

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

8 People are following this question.

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

Related Questions

Hello there I have a Instantiate Issue 0 Answers

Cannot destroy the SphereCollider on Instantiated Objects 1 Answer

Script removing rigidbody component, NOT game object 1 Answer

In need of some help with clones! 1 Answer

Instantiate keep on cloning my object - How can I stop it!? 0 Answers


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