This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

applying different textures to same node

sioncosionco Posts: 40Member
edited December 1969 in 3D
Hi!, I have 13 players in my team, they are all individual nodes, but they are instances of the same player nodes (as you can see player2 and player3 are the are instances of the same node which contains the object and everything):<br />lA3VpR7l.png<br /><br />The model used and created in Blender has two textures, one for the kit, and one for the skin, I want to have the same kit, but have different skin textures, so I can have black and white players.<br /><br />However, when I use the following code (the second one after the for loop is for the skin) and try and change the skin material for one player, it changes it for all of them.<br />So, in this case the last player has the skin2 texture, which means that all the other players also have this skin.<br /><br />
<br />for i in range(1,14):	<br />	get_node(&quot;Team2/Player&quot;+str(i)+&quot;/Spatial/Armature/Skeleton/Cube&quot;).get_mesh().surface_get_material(2).set_texture(0,team2Kit)<br /><br />get_node(&quot;Team1/Player1/Spatial/Armature/Skeleton/Cube&quot;).get_mesh().surface_get_material(0).set_texture(0,skin1)<br />get_node(&quot;Team1/Player2/Spatial/Armature/Skeleton/Cube&quot;).get_mesh().surface_get_material(0).set_texture(0,skin1)<br />get_node(&quot;Team1/Player3/Spatial/Armature/Skeleton/Cube&quot;).get_mesh().surface_get_material(0).set_texture(0,skin2)	<br />
<br />


  • nunodonatonunodonato Posts: 11Member
    that's because they are all using the same material, and you are changing part of that material.<br />when way to do it, is to duplicate the material on _ready for each of the players
  • sioncosionco Posts: 40Member
    Thanks, but I can't work this out<br /><br />
    var mat =get_node(&quot;Team2/Player7/Spatial/Armature/Skeleton/Cube&quot;).get_mesh().surface_get_material(0).duplicate()<br /><br />	mat.set_texture(0,skin2)<br />	mat.set_texture(2,team2Kit)<br />	get_node(&quot;Team2/Player7/Spatial/Armature/Skeleton/Cube&quot;).get_mesh().surface_set_material(0,mat)<br />	get_node(&quot;Team2/Player7/Spatial/Armature/Skeleton/Cube&quot;).get_mesh().surface_get_material(0).set_texture(0,mat.get_texture(0))
  • sioncosionco Posts: 40Member
  • sioncosionco Posts: 40Member
    I've worked it out.<br /><br />On the property editor/inspector for each node, I went to the mesh, and clicked the little cog button and then selected make sub-resources unique

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.