Changed MaterialAsset::GetPropertyValues to not auto-finalize. Client code must call Finalize manually. It's better to avoid unexpected side-effects from a const getter function.

In some cases it may be acceptable to do non-const things in a const function as long as it is only manipulating internal data, and the public facing API returns the same values as before. But in this case, the IsFinalized function is a public facing API that would have a different result after GetPropertyValues was called.

I also updated a couple other minor things from code review feedback.

Signed-off-by: santorac <55155825+santorac@users.noreply.github.com>
This commit is contained in:
santorac
2022-01-14 10:49:17 -08:00
parent 8084775d7a
commit 2d6d14abf7
8 changed files with 35 additions and 28 deletions
@@ -199,10 +199,7 @@ namespace AZ
const AZStd::vector<MaterialPropertyValue>& MaterialAsset::GetPropertyValues() const
{
// This can't be done in MaterialAssetHandler::LoadAssetData because the MaterialTypeAsset isn't necessarily loaded at that point.
// And it can't be done in PostLoadInit() because that happens on the next frame which might be too late. So we finalize just-in-time
// when properties are accessed.
const_cast<MaterialAsset*>(this)->Finalize();
AZ_Error(s_debugTraceName, IsFinalized(), "MaterialAsset must be finalized before its property values can be accessed");
return m_propertyValues;
}