Is the issue about the KinematicBody not having the method on the first script, or the second script?
If it is the first script, maybe try this and see if it works?
extends spatial
onready var spawner_white_pawn = preload("res://scenes/WhitePawn.tscn")
func _ready() -> void:
var b1 = spawner_white_pawn.instance()
b1.set_translation(Vector3(0,5,0))
# assuming the root node in the WhitePawn scene is called
# "WhitePawn", we can skip it and just try to get the MeshInstance node from
# the scene
b1.get_node("Pawnmtl")
# since material is a new variable, we need to add "var"
var mat = b1.get_surface_material(0)
# the color property for the albedo map is called
# "albedo_color"
mat.albedo_color = Color(0, 0, 0, 1)
add_child(b1)
Based on the error, the issue seems to be that the node that is having get_surface_material
called on it is a KinematicBody node rather than a MeshInstance, so that means we're getting the wrong node.
If it is the second script, then the issue is probably that the script needs to get the MeshInstance node first. If it's a child node called Pawnmtl
, then the second script's _ready
function should be adjusted to the following:
func _ready():
var material = get_node("Pawntml").get_surface_material(0)