Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 edgaralexanderfr · Apr 15, 2016 at 04:40 AM · meshtexture2dgenerationprocedural-terraindynamic mesh

Dynamic texture is visible in editor but pink when is built

I know this thread may sound 'repetitive', but I've been researching in other posts trying to follow possible solutions with no luck...

I have a small script for creating a really basic terrain procedurally, in order to archive this first I create a mesh with its respectives vertices, uvs and triangles (I simply want a flat 2D rectangle that I could use as a level background for my game). Then I create a Texture2D with a 1024x1024 resolution that I apply to it, generating random green pixels.

I apply, scale, and finally add a shader (Unlit/Transparent), in order to remove the dark from my mesh.

When I run my game in the editor everything works fine, mesh and texture is rendered as desired, however, when I build my project and run the executable the mesh is pink, this is my code:

 using UnityEngine;
 using System.Collections;
  
 public class TerrainScript : MonoBehaviour {
   void Start () {
     const ushort Width  = 1024;
     const ushort Height = 1024;
     const byte MinColor = 128;
     const byte MaxColor = 200;
     Mesh mesh = new Mesh();
     mesh.vertices = new Vector3[] {
       new Vector3( 1,  1, 0),
       new Vector3( 1, -1, 0),
       new Vector3(-1,  1, 0),
       new Vector3(-1, -1, 0)
     };
  
     mesh.uv = new Vector2[] {
       new Vector2(1, 1),
       new Vector2(1, 0),
       new Vector2(0, 1),
       new Vector2(0, 0)
     };
  
     mesh.triangles = new int[] {0, 1, 2, 2, 1, 3};
     mesh.RecalculateNormals();
  
     Texture2D Texture  = new Texture2D(Width, Height, TextureFormat.ARGB32, false);
     //Texture.filterMode = FilterMode.Point;
     ushort i, j;
  
     for (i = 0; i < Width; i++) {
       for (j = 0; j < Height; j++) {
         Texture.SetPixel(i, j, new Color(0.0f, Random.Range(MinColor, MaxColor) / 255.0f, 0.0f));
       }
     }
  
     Texture.Apply();
  
     GetComponent<MeshFilter>().mesh               = mesh;
     GetComponent<Renderer>().material.mainTexture = Texture;
     GetComponent<Renderer>().material.shader      = Shader.Find("Unlit/Transparent");
     transform.localScale                          = new Vector3(20.0f, 20.0f, 0.0f);
     }
  
     void Update () {
  
     }
 }
  

I read that when this happens is because Unity has a problem locating the resource or the mesh itself is causing the problems. However, I tried by going to Edit > Project Settings > Graphics and adding one index to the shaders array with the used shader Unlit/Transparent as value, built again, same result.

I tried also by commenting the line where I apply the texture so it would look darker but ignore the shader, still pink, so I suspect it may be a problem with the mesh or the texture, I tried by creating an external texture, loading it in the script, resizing it and changing the pixels and I get the same.

If anybody has an idea of what I'm doing wrong or knows if there's a better way to archive what I want I will appreciate it...

Thank you...

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
0

Answer by Paul-Jan · Apr 15, 2016 at 12:45 PM

From the documentation (emphasis mine):

Note that a shader might be not included into the player build if nothing references it! In that case, Shader.Find will work only in the editor, and will result in pink "missing shader" materials in the player build. Because of that, it is advisable to use shader references instead of finding them by name. To make sure a shader is included into the game build, do either of: 1) reference it from some of the materials used in your scene, 2) add it under "Always Included Shaders" list in ProjectSettings/Graphics or 3) put shader or something that references it (e.g. a Material) into a "Resources" folder.

I'm a bit confused by your description, if you mean to say you already added the shader to Always Included Shaders... could you please post a screenshot of the GraphicsSettings inspector so we can verify you did this correctly?

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 edgaralexanderfr · Apr 16, 2016 at 01:45 AM 0
Share

Hello Paul, thank you for your answer,

These are my current graphics settings:

Graphics settings screenshot

As I wrote in my description, it doesn't seem like a shader problem, I believe it's more related with the texture/mesh itself, because when I comment the line where I apply the shader (IOW, I just ignore it and shouldn't be imported), and build my project, the resulting shape is still pink, and when I build with the shader it's white.

screen.jpg (168.8 kB)

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

creating a mesh procedurally 4 Answers

How to resave generated meshes with Editor Scripts? 0 Answers

Starting mesh generation thread before changing chunk transform position 1 Answer

Realtime lighting with generated mesh causes light bleed at seams / edges (minecraft clone) 2 Answers

Mesh building changes in Unity 3.5.6 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