#client can't generate texture

1 messages · Page 1 of 1 (latest)

floral rivet
#

Hi, I'm making a perlin noise based texture, and i wanted the texture to be the same for all clients. Now it only generates texture for the host and all clients are getting is a blank/white texture. Can someone help?
code:
private void Start()
{
map = GetComponent<Renderer>();

    if (IsHost)
    {
        scale = UnityEngine.Random.Range(1, 9);
        offsetX = UnityEngine.Random.Range(0, 100);
        offsetY = UnityEngine.Random.Range(0, 100);
        SendParamsClientRpc(scale, offsetX, offsetY);
        genMap(scale, offsetX, offsetY);
    }
}

void genMap(float scale, float offsetX, float offsetY)
{
    Texture2D txt = new Texture2D(width, height);

    //Perlin noise
    for (int x = 0; x < width; x++)
    {
        for (int y = 0; y < height; y++)
        {
            Color color = calcColor(x, y, scale, offsetX, offsetY);
            txt.SetPixel(x, y, color);
        }
    }

    for (int i = 0; i < 125; i++)
    {
        darkPoints.Add(darkSpots[UnityEngine.Random.Range(0, darkSpots.Count)]);
    }
    darkSpots.Clear();

    txt.Apply();
    map.material.mainTexture = txt;
}

[ClientRpc]
private void SendParamsClientRpc(float scale, float offsetX, float offsetY)
{
    genMap(scale, offsetX, offsetY);
}
wind turret
#

This may not directly be your issue, but avoid sending Rpcs in Start.

#

Use a network related event function like OnNetworkSpawn instead.

#

Also be aware that most Random functions use some auto generated seed to generate their random values. You'll want to the server to use a specific seed and send that to clients to use as well.

true saffron
#

I would use a network variable if late joining clients would need the seed