• 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 BerggreenDK · Jun 28, 2011 at 11:54 AM · prefabs

Load a lot of Prefab on start

I have a sort of tilebased world. Not real tiles, just a LOT of objects put into a matrix kinda grid.

I am looking for good ideas of how to load these into GameObjects without having to code/copy-paste an extra line of GameObject.Resource.Load("xyz") for each time our artist designs a new object for ground, walls, obstracles, bonus-items etc.

I was t$$anonymous$$nking of loading all resources into an array og GameObjects, but then I need to figure out w$$anonymous$$ch goList[xyz] is what Prefab.

Reason is that the map/world is build up from loading levels from a webserver, so we get values/codes for w$$anonymous$$ch tile/prefab to init where. Multiple initations of same prefab on a world map.

Note: We currently use the Indie/free edition, so Assetsbundle is not an option. Once our game experience with Unity3D gets big enough and we are earning money t$$anonymous$$s WILL be our main priority, but right now we have to stick with the Indie version.

Comment
Add comment · Show 2
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 Sirex · Jun 28, 2011 at 12:15 PM 1
Share

What if you make multiple GameObject arrays divided according to meaning? For example one for walls and obstacles. Then you can narrow search functions when you want to find one specific prefab.

avatar image BerggreenDK · Jul 19, 2011 at 09:14 AM 0
Share

@Sirex - this is partly how we have made the SQL database already, so yes absolutely.

2 Replies

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

Answer by BerggreenDK · Jul 19, 2011 at 09:11 AM

I found a way last night.

First I make a static/global array of GameObjects:

 // notice its the generic Object and not GameObject! 
 public Object[] models; 



Inside init code, like Start or whereever, I place t$$anonymous$$s one

 models = Resources.LoadAll("Models", typeof(GameObject));
   

Explanation:

Now I have a complete list of all imported models wit$$anonymous$$n the Models folder in Assets \\ Ressources \\ Models \\

Btw. The Resources.LoadAll, returns a Object[] array, and I haven't been able to typecast it into GameObject, but t$$anonymous$$s works fine(?)

Test it:

 for (int cnt=0; cnt< models.Length; cnt++)
 {
    // lets iterate through them and show their names
    Debug.Log("model #"+ cnt + " is: " + models[cnt].name);
 }


Usage:

Whenever you need them dynamically on the scene, you can run through the models[] array, either keep the index of the ones you need most or search by name.

Then instantiate them as needed:

 int spawn = 52; // if loaded object #52 is your wanted object
 GameObject go = (GameObject) Instantiate( models[spawn], 
                  new Vector3(xpos, ypos, zpos) , Quaternion.identity);

From here you can do to the go object what you need. Such as parent transform, movement, assign components etc.

Why do it t$$anonymous$$s way?

As many of our levels are dynamically generated, we dont use the Unity3D editor for levelediting.

We build a LOAD of .fbx files from Blender or other 3D utils and the artists do not use Unity3D for placement and we just have a large folder + our own assetmanagement server/database.

When the artist registrates the .fbx wit$$anonymous$$n our server, we need to be able to pull these into the game to place on the levels too. T$$anonymous$$s makes it possible for us to code our own custom level/prefab editor and keep our growing structure outside the Unity3D editor.

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
avatar image
1

Answer by Waz · Jun 28, 2011 at 12:54 PM

An array (or multiple) is the way to go, so the artist can just drag it in. Rather than making it an array of GameObject, make it an array of (say) Info, w$$anonymous$$ch you make as a very simple script like:

 var name : String;

if needed, add other stuff:

 enum Category { Rock, Tree, ....... }
 var category : Category;

The artist then adds an Info to the prefab and drags it into the array.

Alternatively, make it an array of struct like t$$anonymous$$s:

 class Info {
     var name : String;
     var prefab : GameObject;
     ...
 }

The artist then adds an element to the array and fills out the details, including dragging in the plain GameObject prefab.

Either style is pretty comfortable for both you and the asset artist.

Also note that using Resource severely limits the value of incremental/streamed level loading, since all Resources are effectively built into level 0 - I.e. not$$anonymous$$ng can start until they are all loaded. In general, Resources are dangerous for web deployed games (the one t$$anonymous$$ng I hate about the Detonator framework is its excessive use of Resources, w$$anonymous$$ch immediately bloat your game even if you don't use the associated explosion types).

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 BerggreenDK · Jun 28, 2011 at 01:29 PM 0
Share

Didnt know that about level 0. But how would you know which resources to load then? another serverscript? and how can the artist drag it in without access to Unity? (I can only use a single .unity3D file for the level I guess, until we have the PRO edition)

avatar image Waz · Jun 28, 2011 at 02:56 PM 0
Share

You can choose a level other than 0 so that you can get a main menu up fast (see First Streamed Level With Resource in Player settings), but that just delays the inevitable. It really depends on you game, and we're getting off the Q subject, but maybe LoadLevelAdditive would allow you to delay some objects until your server says they're needed. It all depends just how big your assets are though. Most users are going to have gotten a whole 5MB unity3d file before they've found the Play button. And it's all for nought if the first thing they do is walk to the tile that needs assets from level 99!

avatar image BerggreenDK · Jul 18, 2011 at 11:35 PM 0
Share

Hmm... only problem with your suggestion right now is that the artist does not use Unity3D editor for designing. He uses Blender, I then import his FBX and from a SQL server we know which FBX makes up a Prefab etc. So I need to be able to automatically load all these.. somehow.

avatar image Waz · Jul 19, 2011 at 01:37 AM 0
Share

Definitely that sounds like a job for AssetBundles. I suggest you ignore the slowness until you're ready to get Pro. Note that the Profiler alone is worth a good chunk of the cost, and developing anything without it is inefficient use of time.

avatar image BerggreenDK · Jul 19, 2011 at 09:13 AM 0
Share

Not really what we are looking for. We do go for pro because of the render effects and shadows, but the reason is more how we work with the project. I've posted my own solution now. Thanks for your effort, eventhough it wasnt what I was looking for. :-)

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to fix the problem of object instantiating partially? 0 Answers

Line from Parent to Children on UI 0 Answers

How would I go about storing spawned prefabs to acces them ? 3 Answers

What files are responsible for script components on prefabs? 2 Answers

When creating a 2D array as a grid of cubes they are all the same colour,My array of gameObjects are all the same colour, even when I set them differently 2 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