Search Unity

Question Materials not properly swapping on preview

Discussion in 'Shaders' started by Taykin4, Jan 17, 2024.

  1. Taykin4


    Jan 4, 2024
    Game pieces from my prefabs are not swapping materials as expected

    Sample of the code I use

    private Pieces SpawnSinglePiece(PieceCurrent current, int team){

    Pieces current_piece = Instantiate(prefabs[(int)current - 1], transform).GetComponent<Pieces>();

    current_piece.current = current; = team;
    current_piece.enabled = true;
    current_piece.GetComponent<MeshRenderer>().material = teamMaterials[team];
    return current_piece;


    When executed prefabs spawn, but with the default blank material, but the inspector shows the right material in the mesh Renderer


    Very confused as to why it doesn' show. I've trided calling getcomponentinchildren, as manually changing the children in each piece seemed to change it but to no avail the script would not work. I tried using less complicated material, ones with no normal or textures backed into them.... but same issue

    I am very confused and have been for a few days now please help