Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 kiryu_kazuma123 · Sep 17, 2021 at 11:41 AM · scripting problemmeshobjectmeshcolliderresources.load

Cannot add Mesh via script

Hi there! I want to add a Mesh to Mesh Collider of an object. I'm trying the code below:

         GameObject headd = Resources.Load("Art/Prefabs/head") as GameObject;
         headd.name = "heaed";
         GameObject head = Instantiate(headd);
         head.transform.rotation = Quaternion.Euler(0.0f, 180.0f, 0.0f);
         Destroy(head.GetComponent<SphereCollider>());
         head.AddComponent<MeshRenderer>();
         head.AddComponent<MeshCollider>();
         head.GetComponent<MeshRenderer>().material = AssetDatabase.GetBuiltinExtraResource<Material>("Default-Diffuse.mat");
         head.GetComponent<MeshCollider>().sharedMesh = Resources.Load<GameObject>("Art/Prefabs/head").GetComponent<Mesh>();
         head.name = "Model";
         head.transform.SetParent(headGO.transform);

When I run the scene, the Mesh Collider's mesh is still shown as "None" like this. alt text

That part of code:

 Resources.Load<GameObject>("Art/Prefabs/head").GetComponent<Mesh>();

returns null. I could not understand why it behaves like this. I have to get Mesh from the .obj file which located in that location.

Also, this is the folder hierarchy of the project which I want to load object and objects mesh from... alt text

Thanks....

screenshot-2021-09-17-141314.png (53.3 kB)
screenshot-2021-09-17-141314.png (53.3 kB)
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 Hellium · Sep 17, 2021 at 11:39 AM 0
Share

Please edit your question and provide a screenshot of the head object in your Project tab.

Keep in $$anonymous$$d that Resources.Load looks for assets in a subfolder of a Resources folder.

avatar image kiryu_kazuma123 Hellium · Sep 17, 2021 at 12:01 PM 0
Share

Yeah I know, I added the screenshot which shows the path I want to load it from, the problem is not the path I think...

1 Reply

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

Answer by tonaros1 · Sep 17, 2021 at 12:17 PM

Hi, @kiryu_kazuma123.

The answer is very simple.

In order to get a mesh from an .obj file, you need to refer to its child object and request the MeshFilter component from it.

For example like this:

 var meshFilter = Resources.Load<GameObject>("Art/Prefabs/head").GetComponentInChildren<MeshFilter>();
 GetComponent<MeshCollider>().sharedMesh = meshFilter.sharedMesh;





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 kiryu_kazuma123 · Sep 17, 2021 at 01:30 PM 0
Share

That worked! Thank you so much...

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

250 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 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 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 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 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 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 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 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 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 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 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 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 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 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

Changing Mesh and Mesh Collider of an Object 0 Answers

Generated meshcollider is not working? 1 Answer

Get the triangles of a convex mesh collider 1 Answer

Polybrush is not updating the mesh collider? 2 Answers

Splitting a Mesh into Submeshes 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