Unity Network Spawn not sending custom settings

40 Views Asked by At

PROBLEM SOLVED thanks to hijinxbassist In the below codes i changed the SetUp function to SetUpClientRpc and called it after i spawned the tiles.

I'm trying to create a grid through the network, and everyone get the same grid. When the grid piece is instantiated i will set a random sprite and a color. On the host which is the server the grid looks good. But then when the piece is spawned on the network it is the default prefab that is spawned not the altered grid piece.

The code for the tile is this

public class Tile : NetworkBehaviour
{
    public SpriteRenderer spriteRenderer;
    public Vector2Int gridLocation;

    public void SetUp(Sprite _tileSprite, Vector2Int _gridLocation, Color _tileColor)
    {
        spriteRenderer.sprite = _tileSprite;
        gridLocation = _gridLocation;
        spriteRenderer.color = _tileColor;
    }

    private void Awake()
    {
        spriteRenderer = GetComponent<SpriteRenderer>();
    }
}

The code that spawns it is this

for (int x = 0; x < _ThisLevel.GridWidth; x++)
{
    for (int y = 0; y < _ThisLevel.GridHeight; y++)
    {
        Tile nTile = Instantiate(usetile, tileLocation, Quaternion.identity);
        nTile.SetUp(
            _ThisLevel.tileSprites[Random.Range(0, _ThisLevel.tileSprites.Count)],
            new Vector2Int(x, y),
            tileColor
            );
        nTile.GetComponent<NetworkObject>().Spawn(true);
        tileLocation += Vector2.down * (_ThisLevel.GridSpacing);
    }
    tileLocation.y = startLocation.y;
    tileLocation += Vector2.right * direction * (_ThisLevel.GridSpacing);
}

Client and host are different

0

There are 0 best solutions below