• 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 jzhang1 · Aug 19, 2013 at 06:37 PM · assetdatabase

AddObjectToAsset backwards from documentation?

According to documentation, AddObjectToAsset has signature AddObjectToAsset(Object objectToAdd, Object assetObject);

This implies that the child object is first, and main object is second. But when I call it, AddObjectToAsset(a, b) and then use AssetDatabase.IsSubAsset I get a is not, and b is. It's creating things backwards.

Comment
Add comment · Show 7
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 jzhang1 · Aug 19, 2013 at 06:55 PM 0
Share

Just to add, I'm using a custom asset with extention .asset

avatar image jzhang1 · Aug 19, 2013 at 07:13 PM 0
Share

This is roughly what I have

 class A : ScriptableObject {}
 A a = new A();
 AssetDatabase.CreateAsset(a, path);
 
 Texture2D t = new Texture2D(16,16);
 AssetDatabase.AddObjectToAsset(t, a);
 AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(t));

I end up with the texture as the main asset and A as the subasset.

avatar image jzhang1 · Aug 19, 2013 at 07:16 PM 0
Share

Is it not possible to make a custom asset the $$anonymous$$ain asset?

avatar image Benproductions1 · Aug 20, 2013 at 02:04 AM 0
Share

If it's the wrong way around, then it's the wrong way around. I don't understand what the problem is????

avatar image jzhang1 · Aug 20, 2013 at 03:15 AM 0
Share

There is no way to make it right then. $$anonymous$$ore importantly, this behavior only happens with custom assets. If I use built in assets it works correctly. I don't understand why custom assets can't be the main asset when adding subassets

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by yoyo · Jan 13, 2014 at 09:22 PM

The API documentation is correct, but when you first add a child object to a custom asset the asset and the child both become children of a new asset of type "Object".

You can witness this behaviour by looking at the asset in the Project panel. It will go from looking like this:

 (ScriptIcon)MyAsset

to this:

 (BlankIcon)MyAsset
     (ScriptIcon)ChildAsset
     (ScriptIcon)MyAsset

Where the top-level MyAsset is of type UnityEngine.Object. Note that right-click Reimport doesn't make any difference, but if you right-click Reimport All then the order will change so that your original asset is first in the list:

 (BlankIcon)MyAsset
     (ScriptIcon)MyAsset
     (ScriptIcon)ChildAsset

This is what I'm seeing in Unity 4.3.1, using custom classes derived from ScriptableObject for both MyAsset and ChildAsset.

I expect it behaves this way because ScriptableObject is not a "container" asset, so it can't contain children. Other asset types are designed to contain nested assets, for example an animation contains animation clips.

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 Xelnath · Mar 20, 2015 at 01:04 AM 0
Share

How do I get a list of the children of an object who has had an asset added to it?

e.g. I want to print a list of all animation clips stored inside a prefab.

avatar image MattRix · Jul 28, 2015 at 06:52 PM 0
Share

@Xelnath you should be able to use AssetDatabase.LoadAllAssetsAtPath http://docs.unity3d.com/ScriptReference/AssetDatabase.LoadAllAssetsAtPath.html

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

18 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

Related Questions

Determining which Asset is connected to a GameObject. 3 Answers

Where are asset labels stored? 1 Answer

Get prefab's path in file system 2 Answers

Only PostProcess/PreProcess on new assets 1 Answer

Asset Database and Inventory System 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