Search Unity

Issue with Mesh and textures

Discussion in '2D' started by jens454, Jul 21, 2016.

  1. jens454

    jens454

    Joined:
    Jul 21, 2016
    Posts:
    2
    Hi,

    I am trying to create a randomly generated world and to this I have used the following approach:

    1) Create a number of (random) meshes in code to represent the world
    2) Applying a material to the generated mesh
    3) Add the mesh to the world as a gameobject

    My issue is that the textures gets a single color instead of the actual texture and I cannot for the life of me figure out why this happens.

    Example world that was genereated:


    This is the water mesh that was generated as seen above:

    And the mesh:

    And the texture that should have been applied based on the material looks like:

    I really hope someone can give as to what I am doing wrong?
    If it just create a simple plane mesh in the editor and apply the material it looks correct so I guess it is something to do with my mesh but I cannot figure out what I am doing wrong.

    Some code:
    Mesh created by:

    GameObject gameobject = new GameObject("Gameobject: " + itemToRender.material.name);
    MeshFilter meshFilter = (MeshFilter) gameobject.AddComponent(typeof(MeshFilter));
    meshFilter.mesh = itemToRender.mesh;
    MeshRenderer renderer = gameobject.AddComponent(typeof(MeshRenderer)) as MeshRenderer;
    renderer.material = itemToRender.material;

    Where the material is loaded before using:
    AssetDatabase.LoadAssetAtPath<Material>(materialLocation);

    The end goal is to show the mesh using:
    UnityEngine.Graphics.DrawMesh(iitemToRender.mesh, Vector3.zero, Quaternion.identity, itemToRender.material, 0);

    for better performance as I want to generate a rather large world and it looks like the mesh is created correctly I just cannot figure out how to get the texture to show correctly.

    Thanks in advance for any feedback! :)
     
  2. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,807
    Well, the fact that it's receiving a color from your texture makes me think that it's at least partially working.

    Perhaps try Unlit/Texture shader and adjust the tiling?
     
  3. jens454

    jens454

    Joined:
    Jul 21, 2016
    Posts:
    2
    Thanks for the answer.
    The issue was with the tiling that I did not apply correctly.
    After applying the tiling correctly it now looks like it should.
    Thanks!
     
    LiterallyJeff likes this.