Page MenuHomeFeedback Tracker

Can't get materials from prefab source
Closed, ResolvedPublic

Description

Im trying to get all materials from a prefab but it always returns 0 materials. A prefabs should return all assigned materials.

Only the M923A1 returns a single material. Not sure why.

I tried a couple different methods but all fail to return all materials:

ResourceName modelPath;
string remap;
SCR_Global.GetModelAndRemapFromResource("{3F2AA823B6C65E1E}Prefabs/Vehicles/Wheeled/M923A1/M923A1_transport_MERDC.et", modelPath, remap);
Print(modelPath);
Print(remap);

->
ResourceName modelPath = '{DF7CF60669EFC7E5}Assets/Vehicles/Wheeled/M923A1/M923A1_BASE.xob'
string remap = '$remap 'M923A1_Base' '{7463EDCC42A45CFB}Assets/Vehicles/Wheeled/M923A1/Data/M923A1_Base_MERDC.emat';'

----

IEntityComponentSource itemComponentSource = SCR_BaseContainerTools.FindComponentSource(Resource.Load("{3F2AA823B6C65E1E}Prefabs/Vehicles/Wheeled/M923A1/M923A1_transport_MERDC.et"), MeshObject);
BaseContainerList meshMaterials = itemComponentSource.GetObjectArray("Materials");
PrintFormat("Mesh has %1 materials", meshMaterials.Count());

->
Mesh has 1 materials

Details

Severity
Minor
Resolution
Open
Reproducibility
Always
Operating System
Windows 10 x64
Category
General

Event Timeline

Geez changed the task status from New to Assigned.Jan 4 2023, 2:20 PM

Hello, you should load the mesh object itself and then ask for the material to actually get the materials of a prefab. See the example below.

Resource resource = Resource.Load("{29EA7C7ADF66D388}Prefabs/Rocks/Granite/Granite_BeachCluster_02.et");
IEntityComponentSource itemComponentSource = SCR_BaseContainerTools.FindComponentSource(resource, "MeshObject");
ResourceName resourceNameObject;
if (itemComponentSource.Get("Object", resourceNameObject))
{
	MeshObject meshObject = Resource.Load(resourceNameObject).GetResource().ToMeshObject();
	if (meshObject)
	{
		string materials[256];
		int materialsCount = meshObject.GetMaterials(materials);
		PrintFormat("Mesh has %1 materials", materialsCount);
	}
}
Geez closed this task as Resolved.Jan 11 2023, 11:55 AM
Geez claimed this task.