Jump to content

Do TerrainMaterials need a Material for their diffuseMap?


Recommended Posts

I'm trying to get a rid of the missing material warning for TerrainMaterial:

 [MaterialList::mapMaterials] Unable to find material for texture: [matName]

After comparing with fullTemplate, I realized that all TerrainMaterial have a Material defined for the diffuseMap, what is it needed for? Just to get rid off the warning?

I remember a while back I was making a Material for each of my TerrainMaterial but I lost this habit and I don't see a difference. I just want to know if I'm missing something, is there a use for the extra Material or it's just in case you need the TerrainMaterial as standard material?

If it's not needed, anyone have a solution to get rid of the warning?

Link to comment
Share on other sites

Terrain materials don't need a standard material, but there is a case where they do, there are Terrain_FX materials that define some settings like footstep sound, decals, particle effects etc.

So you need a "new TerrainMaterial()" and a "singleton Material(TerrainFX_)

No idea why, but it works that way.

Link to comment
Share on other sites

Well since I'm lasy and don't like having to write extra Material, I made a TerrainMaterial fix function that check all TerrainMaterial in art/terrains folder. It create a new material file with a pre_ prefix containing all diffuseMap with missing Materials.

Here's the initial version in case someone want to use it, it's a quick scripting job but it do the job and save time writing material. Also you can use the %reset to regenerate all the materials. The %loadNew var is for loading the new Material file instantly once created . For future updates, it will be included in my helpers collection.

function fixTerrainMaterialsStock(%loadNew,%reset) {
%searchFolder = "art/terrains/*materials.cs";

//Now go through each files again to add a brush with latest items
for(%matFile = findFirstFile(%searchFolder); %matFile !$= ""; %matFile = findNextFile(%searchFolder)) {
	%fileObj = new FileObject();
	// Open a text file, if it exists
	%folder = filePath(%matFile);
	%fileBase = fileBase(%matFile);
	%newMatFile = %folder@"/pre_"@%fileBase@".cs";
	%fileWrite = "";

	while( !%fileObj.isEOF() ) {
		%line = %fileObj.readLine();

		if (strFind(%line,"TerrainMaterial")) {
			%inTerrainMaterial = true;
		} else if(%inTerrainMaterial && strFind(%line,"diffuseMap")) {
			%lineFields = strreplace(%line,"\"","\t");
			%difMap = getField(%lineFields,getFieldCount(%lineFields)-2);
			%difMapName = fileBase(%difMap);
			%matObj = "Mat_"@%difMapName;
			%matObj = strReplaceList(%matObj,"-" TAB "_" NL " " TAB "_");

			if (isObject(%matObj) && %reset)

			if (!isObject(%matObj)) {
				if (!isObject(%fileWrite)) {
					%fileWrite = new FileObject();
					%fileWrite.writeLine("//Auto generated material for TerrainMaterial in:"@%fileBase@"");
					%fileWrite.writeLine("info(\"Loading generated materials for:"@%fileBase@"\");");

				%fileWrite.writeLine("singleton Material("@%matObj@")");
				%fileWrite.writeLine("	mapTo = \""@%difMapName@"\";");
				%fileWrite.writeLine("	footstepSoundId = 0;");
				%fileWrite.writeLine("	terrainMaterials = \"1\";");
				%fileWrite.writeLine("	ShowDust = \"1\";");
				%fileWrite.writeLine("	showFootprints = \"1\";");
				%fileWrite.writeLine("	materialTag0 = \"Terrain\";");
				%fileWrite.writeLine("	impactSoundId = 0;");
		} else if (strFind(%line,"};")) {
			%inTerrainMaterial = false;

	if (isObject(%fileWrite)) {
		if (%loadNew) 


You could then simply paster the new material file before your terrain materials or to keep the pre_ material file, I have add a check for that file in the loadMaterials function, if the pre_ file is found, it will execute it before executing the standard material file.

Just add this before the exec(%file) in loadMaterials()

%folder = filePath(%file);
%fileBase = fileBase(%file);
%preMatFile = %folder@"/pre_"@%fileBase@".cs";
if (isFile(%preMatFile))

Link to comment
Share on other sites

Yeah, I know but like I said I'm lazy. These days I'm experimenting a lot with terrains and I often change or create materials. With that functions, I can make sure the linked Materials are up-to-date.

It's quite useless for basic use of already develloped materials but it will help me a bit... And I would expand it someday...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...