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
0
Question by Aeal · Mar 17, 2013 at 04:36 PM · editormeshmaterialdynamicgeneration

Creating a mesh and assigning a material during edit time.

Hello all, I am working on some code that will generate layouts from xml files. I am currently trying to make plane in code and assign it a material based on the imported xml file. However I have run into a few issues. When I create the plane on its own with no material every thing works fine. I get a plane with the ugly purple color, but when I set the material on the plane the mesh disappears in the inspector.

 var loader = (frameObjectInfo.info as QuickBackdropLoader);
                 int imageHandle = loader.ImageHandle;
                 go = synPlaneUtility.CreatePlane(1, 1, loader.Width, loader.Height);
                 //Material mat = new Material(Shader.Find("Diffuse"));
                 if(go.renderer.sharedMaterial == null)
                 {
                     go.renderer.sharedMaterial = new Material(Shader.Find("Diffuse"));
                 }
                 go.renderer.sharedMaterial.mainTexture = textureLibrary[imageHandle]; 

I have tried setting both material and shared material, and setting either one causes the mesh to disappear. Any help would be greatly appreciated

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 Aeal · Mar 17, 2013 at 04:44 PM 0
Share

The mesh generation works fine when I do not assign a material to the mesh. As soon as I try to assign a material to the mesh it disappears. The code for generating the plane is a modified version of the script found here: http://wiki.unity3d.com/index.php/CreatePlane I simply made it so that the function can be called with parameters ins$$anonymous$$d of having to use the wizard.

avatar image robertbu · Mar 17, 2013 at 06:27 PM 0
Share

$$anonymous$$y guess is that you have the normals reversed. That is, you plane is facing down. Try moving your camera in the inspector to view the bottom side (or rotate the plane 180 degrees).

1 Reply

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

Answer by Aeal · Mar 19, 2013 at 02:54 AM

Ok, so after some testing and hair pulling I finally came up with the solution. The problem was not in my mesh generation or material assigning. The problem was the way the code worked as a whole. The importer works in several steps. First it imports all the sprite textures, then it makes prefabs for each object in the layout and then generates the layout itself. When generating the prefab the mesh and material would be dynamically generated. However you cannot have a reference to a dynamically created mesh and material in a prefab (thus why they would disappear when created in layout).

So my solution to the problem was to add the mesh and material to the prefab using the AssetDatabase AddObjectToAsset function, and then load the newly created objects and assign them to the appropriate values in the prefab.

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

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

10 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

Related Questions

Mesh visible in editor but not build 1 Answer

Adding Verticies to Mesh 1 Answer

Why does Frame Selected toggle between position and bounds for procedural and imported meshes? 1 Answer

Multiple materials vs Multiple Meshes. Which is better for performance? 0 Answers

How to set up UV for lightmaps for generated meshes? 4 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