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
0
Question by Bluzeere · Jul 04, 2017 at 11:48 PM · prefabsceneinstancestartupdelete

Preventing first instance of object from starting on screen

I'm making my character throw projectiles at the press of a button. So I created that object in the tree on the left, and when you press the button, I use Instantiante at the character's location.

However this one first instance I created starts in the middle of the screen (where I created it in the Scene editing) and does its launching code before anything happens. Not only that, but when it gets deleted as per normal projectile protocol, the whole class stops working altogether and I can't create any more.

How am I supposed to handle this exactly? I need to 1. Prevent the object from automatically spawning just because it's on my Scene, and just serve as a prefab of which I can create clones which do their thing 2. Find out why this first instance has to exist otherwise clones cannot be created anymore

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
1
Best Answer

Answer by Cornelis-de-Jager · Jul 05, 2017 at 12:11 AM

Why do you want to create clones of a prefab already In the scene? Just reference the prefab from the asset folder. That why you can create clones of an object that is not in the scene. I believe that will solve both your issues. Also add code so we can see how you delete the objects.

Comment
Add comment · Show 2 · 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 Bluzeere · Jul 05, 2017 at 01:20 AM 0
Share

I realize now I was using the prefab term wrong. I did not know about the actual Prefab feature in Unity. I will start with documenting myself about that, thanks for your help.

avatar image Cornelis-de-Jager Bluzeere · Jul 05, 2017 at 03:12 AM 0
Share

Its easy, let me explain how it works.

  1. Create the game object you want in the scene.

  2. Drag it to your asset folder (BOO$$anonymous$$! There you have a prefab)

  3. Delete the object in the scene (it will not be deleted from asset folder)

so if you want to reference them in a script then do this:

 /* Create a variable for the prefab (has to be public or serialized) */
 public GameObject myPrefab; // This is where you drop and drag the object from the asset folder into the inspector
 
 /* Spawn the object  */
 // Spawn the object and leave it alone
 Instantiate (myPrefab, position, rotation, parent);
 
 // Spawn the object and manipulate it via code
 GameObject obj = Instantiate (myPrefab, position, rotation, parent) as GameObject;
 
 // The you can do with the newly spawned object what you want
 obj.GetComponent<BehaviorName> ().DoSomething ();




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

90 People are following this question.

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

Related Questions

Cost of loading manually modified instances at runtime, on mobiles? 1 Answer

Passing array of prefabs to next scene 1 Answer

How (and where) does Unity save the modified parameters of a prefab's instance? 1 Answer

Delete prefab in resource folder 0 Answers

How to do not apply fields in prefab 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