Before updating to Windows 10 you may need to return your Pro license. More information here

How to load Assets as GameObjects?

I'm writing an Editor script that takes assets from a directory path, and builds them into an asset bundle.

I want to use: BuildPipeline.BuildAssetBundle(Object main, Object [] assets, string outputPath, ...);

That means I need an array of Object[]. But how do I get the array of Object[], given an asset path that contains all the fbx that I need in bundled?

Additional Analysis:

  1. I can't use Editor's "Selection" API. Because, I can't control what folder is selected in the Editor window.
  2. This doesn't work: Object[] objects = AssetDatabase.LoadAllAssetsAtPath("Assets/Art") , it doesn't load the assets as GameObjects or Texture2D's if I try to cast the Object afterwards. I checked using C# code: if (objects[i] is GameObject), it will return false for all objects in the array. This API works differently from what I assumed. It takes the file path of an asset (ie: /character.fbx), not a folder path, and outputs all children in the fbx as GameObjects.

more ▼

asked Nov 20, 2010 at 12:39 AM

avatar image

51 1 3 6

interesting idea. I will favorite this one.

Nov 20, 2010 at 02:39 AM BerggreenDK
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Why does AssetDatabase.LoadAllAssetsAtPath not work for you? The problem you are havaing with it should be a non-issue. In unity, a asset does not come in as a GameObject. It comes in as the most appropriate class, so a FBX should come in as a Mesh. What I would reccomend doing is instead of checking for a GameObject, print the class name. Try

foreach (object o in objects) Debug.Log(object.GetType().ToString());

which should give you the class names of all the imported objects.

Is your output asset bundle working? I find that is the really important question.

more ▼

answered Nov 30, 2010 at 03:35 AM

avatar image

1.4k 22 19 41

Inside that foreach loop you can do things like "if (o is Mesh)" to find the objects of the type(s) you're interested in.

Dec 03, 2010 at 06:47 PM yoyo
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Nov 20, 2010 at 12:39 AM

Seen: 3392 times

Last Updated: Nov 20, 2010 at 12:53 AM