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
1
Question by DaveA · Jul 28, 2010 at 08:28 PM · meshmaterialassetassign

Assigning meshes & materials from Assets, how?

I know this must be plainly simple, but still it eludes me:

I want to create a mesh and/or material (in an Editor script), and I want to assign a mesh from my assets. Not necessarily in Resources folder mind you, just some random asset.

something like:

gameObject.GetComponent(MeshFilter).sharedMesh = ?LoadAsset? ("big_gun_mesh");

Is this possible?

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 Mike 3 · Jul 28, 2010 at 08:38 PM

You'll want to use AssetDatabase.LoadAssetAtPath:

http://unity3d.com/support/documentation/ScriptReference/AssetDatabase.LoadAssetAtPath.html

It's similar to Resource.Load, but takes paths relative to the project folder, not assets as you may first guess

Comment
Add comment · Show 7 · 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 DaveA · Jul 28, 2010 at 08:49 PM 0
Share

Sounds promising, but is there any way to not use a path? Eg. when you go to the $$anonymous$$eshRenderer, you can drop-down a (non-pathed) list of meshes to choose. That would be nice. Otherwise, I have to crawl my project folder looking for the mesh, which in fact may be a sub-mesh.

avatar image Mike 3 · Jul 28, 2010 at 09:15 PM 0
Share

In that case, I'd just make a wizard with a public mesh property, drag the right mesh in, and do the processing after create

avatar image DaveA · Jul 28, 2010 at 09:31 PM 0
Share

I'm really trying to avoid that 'drag' step all together. I'm making a script to repair 'missing mesh' and 'missing material' problems. I have a ton of them, too much dragging each time.

avatar image Mike 3 · Jul 28, 2010 at 10:02 PM 0
Share

In that case, the only thing I can think of is recurse through the assets using functions from System.IO.Directory, then render them in a selectable list

avatar image DaveA · Jul 28, 2010 at 10:12 PM 0
Share

This can't be really interactive. Actually, I have made some headway. I'm assu$$anonymous$$g a particular path and all files .dae. So when I run into a game object with a $$anonymous$$eshRenderer but no mesh, I load the dae with the same name as the parent of this object, then look in the loaded objects for one that matches the current gameobject's name, with type of $$anonymous$$esh. I then assign this to the shared$$anonymous$$esh property on the mesh filter. This actually seems to work but I'm not thrilled, because the results seem to have some serious clipping plane problems (original, undamaged file had no problems). Also (see next..

Show more comments

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

No one has followed this question yet.

Related Questions

Assign material and guiskin to variables 1 Answer

Beginner: assigning texture to part of GameObject 1 Answer

Is it possible to create a Material _asset_ from a script? 3 Answers

Save procedural mesh in the editor as asset. 2 Answers

Combining SkinnedMesh's with the same material and animations 0 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