Search Unity

Second object changing color to Pink when loading on the scene

Discussion in 'Scripting' started by Robotrol, Nov 8, 2017.

  1. Robotrol

    Robotrol

    Joined:
    Nov 8, 2017
    Posts:
    3
    I developed a C# code that displays in the scene 2 assets a cube and a cylinder in real time, but the second that this inside the cube becomes pink because?

    I need to activate or deactivate something in the Unity Engine?



    Thank you
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,745
    Generally the magenta color comes from something wrong with the material, either an invalid shader so it falls back on diffuse unlit, or missing textures.

    If you are doing this procedurally (i.e., calling CreatePrimitive) and you are building to "outside the editor," then since there is no actual in-build reference to the default diffuse shader, Unity will helpfully strip it from your code and leave you pink. (Sigh!)

    If this is the case, then just drag a prefab of a cube into a folder named Resources so that Unity sees that your final build "needs" it and will include the material/shader.
     
  3. Robotrol

    Robotrol

    Joined:
    Nov 8, 2017
    Posts:
    3
    First, thanks for the help.

    So when I display the cube first after the cylinder, the cylinder turns pink. If I first display the cylinder and then the cube. The cube is pink. And all already have PREFAB in the Resources folder. I am displaying on the screen using the (WWW) and use the (LoadAssett).

    My Code:

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class loadAssetBundlers : MonoBehaviour {
    7.  
    8.     // Use this for initialization
    9.     void Start () {
    10.  
    11.         string url = "https://www.mywebsite.com/cube";
    12.         WWW www = new WWW(url);
    13.         //Debug.Log (www.data);
    14.         StartCoroutine(WaitForReq(www));
    15.     }
    16.  
    17.  
    18.     IEnumerator WaitForReq(WWW www)
    19.     {
    20.         yield return www;
    21.  
    22.         AssetBundle bundle = www.assetBundle;
    23.         if(www.error == null)
    24.         {
    25.             GameObject cube = (GameObject)bundle.LoadAsset("cube");
    26.             Instantiate (cube, new Vector3 (0, 0, 0), Quaternion.identity);
    27.  
    28.             Debug.Log ("Received from Web: " + cube.gameObject);
    29.         }
    30.         else{
    31.             Debug.Log(www.error);
    32.         }
    33.     }
    34. }
    35.  
    Thank You