Swapping out mesh surface materials on scene import

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ace-Dragon
:warning: Old Version Published before Godot 3 was released.

So basically, what I want to do is use a post-process script on the imported scene to swap out materials for the various surfaces surfaces within mesh objects.

I have already tried to follow the (sparse) guidelines in the documentation and wrote this script to do the post-process.

tool # needed so it runs in editor
extends EditorScenePostImport

func post_import(scene):
	var meshInst = scene.get_node('Cube')
	var mesh = meshInst.get_mesh()

	var material1 = load('res://Mat1.mtl')
	var material2 = load('res://Mat2.mtl')
	var material3 = load('res://Mat3.mtl')

	mesh.surface_set_material(0,material1)
	mesh.surface_set_material(1,material2)
	mesh.surface_set_material(2,material3)

The scenario is assuming I have a mesh with three surfaces, and I want to replace the three materials on the mesh with three different materials made in Godot.

In addition, the materials that come with the mesh on import need to have the correct name before the post-process swaps them out, but the problem is that I get an error with what I have so far and there is very little, if any, documentation as to how to actually do anything with that type of script. In addition, the error messages aren’t much help so I don’t know what I did wrong.

Finally, I’m using the 2.1 alpha version of Godot and I’m looking to use this to avoid having to reset all of the materials whenever a level scene is re-imported.

Any suggestions?