Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 haim96 · Aug 15, 2013 at 06:15 AM · instantiateprefabscenevariablefindgameobjectswithtag

Instantiate new object from scratch

Hello,

is there a way to Instantiate a new prefab object without dragging the prefab to public variable or having an existing copy of the prefab in the scene (and use "findGameObjectWithTag" )?

basically i'm trying to fill a List array with some prefabs but the list of prefabs can be changed. so i don't want to drag all of them to variables.

thanks!

Comment
Add comment · Show 3
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 robertbu · Aug 15, 2013 at 06:19 AM 0
Share

Not sure what you are going for here. You can create a new game object:

 var go = new GameObject();

This creates an empty game object. You can add the 'go' to a list or whatever you need. You can also build it up by adding components. Note if you want it to exist at edit time, you will need to fill your array using an editor script.

avatar image haim96 robertbu · Aug 15, 2013 at 07:02 AM 0
Share

not sure this will help me unless the "new GameObject" can be an existing prefab...

this is my scenario: i have some prefabs in my game. i need to add some of them to List Array in specific order for example:

 List.add = prefab1;
 List.add = prefab2;
 List.add = prefab3;

to do that i need to do one of two things:

  1. assign the prefab to public gameobject prefab1 ,prefab2,prefab3...etc

  2. if the prefab already exist in scene i can find it by tag and add to the list (but they not exist in the scene so i can't use this)

the prefabs and order may be changed from level to level. later i want to instantiate these prefab from the List Array by the order they appear.

so, is there another way to do this?

avatar image robertbu · Aug 15, 2013 at 07:35 AM 0
Share

I missed the boat on what you were trying to do, so I've converted my answer to a comment. I thought you were just looking for some placeholder objects, and/or dynamically build a game object. @Jamora's answer will allow you to dynamically fill your list.

1 Reply

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

Answer by Jamora · Aug 15, 2013 at 07:10 AM

You can have your prefabs in a Resources folder. Everything inside a Resources folder will be added to the build - regardless of actually being used - so only add necessary objects.

You can load resources from a Resources folder with Resources.Load during runtime.

Comment
Add comment · Show 1 · 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 haim96 · Aug 15, 2013 at 07:57 AM 0
Share

Yap! this will do the trick, thanks for the help!

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

16 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

Related Questions

What is the type of my prefab? 2 Answers

Change prefab before instantiation 1 Answer

Passing a variable to the child of Instantiated object? 1 Answer

How to Reference Player when Instantiating Prefab 1 Answer

Changing game object based on variable state? 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