MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / load

Method load

Source/Engine/Content/Assets/MaterialInstance.cpp:209–249  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

207}
208
209Asset::LoadResult MaterialInstance::load()
210{
211 // Get main chunk
212 auto chunk0 = GetChunk(0);
213 if (chunk0 == nullptr || chunk0->IsMissing())
214 return LoadResult::MissingDataChunk;
215 MemoryReadStream headerStream(chunk0->Get(), chunk0->Size());
216
217 // Load base material
218 Guid baseMaterialId;
219 headerStream.Read(baseMaterialId);
220 auto baseMaterial = Content::LoadAsync<MaterialBase>(baseMaterialId);
221 if (baseMaterial)
222 baseMaterial->AddReference();
223
224 // Load parameters
225 if (Params.Load(&headerStream))
226 {
227 if (baseMaterial)
228 baseMaterial->RemoveReference();
229 LOG(Warning, "Cannot load material parameters.");
230 return LoadResult::CannotLoadData;
231 }
232
233 if (baseMaterial && !baseMaterial->WaitForLoaded())
234 {
235 _baseMaterial = baseMaterial;
236 OnBaseSet();
237 }
238 else
239 {
240 // Clear parameters if has no material loaded
241 _baseMaterial = nullptr;
242 Params.Dispose();
243 ParamsChanged();
244 }
245
246 if (baseMaterial)
247 baseMaterial->RemoveReference();
248 return LoadResult::Ok;
249}
250
251void MaterialInstance::unload(bool isReloading)
252{

Callers

nothing calls this directly

Calls 10

GetChunkFunction · 0.85
IsMissingMethod · 0.80
WaitForLoadedMethod · 0.80
GetMethod · 0.45
SizeMethod · 0.45
ReadMethod · 0.45
AddReferenceMethod · 0.45
LoadMethod · 0.45
RemoveReferenceMethod · 0.45
DisposeMethod · 0.45

Tested by

no test coverage detected