fix asset refresh on materialAssets

This commit is contained in:
marauder2k7 2025-03-27 18:33:37 +00:00
parent 4d14610753
commit fc30d178af
3 changed files with 13 additions and 31 deletions

View file

@ -334,7 +334,6 @@ void ImageAsset::onAssetRefresh(void)
// Call parent. // Call parent.
Parent::onAssetRefresh(); Parent::onAssetRefresh();
//mLoadedState = NotLoaded;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -577,7 +576,7 @@ void ImageAsset::onTamlPreWrite(void)
return; return;
// Ensure the image-file is collapsed. // Ensure the image-file is collapsed.
mImageFile = getOwned() ? collapseAssetFilePath(mImageFile) : mImageFile; mImageFile = collapseAssetFilePath(mImageFile);
} }
void ImageAsset::onTamlPostWrite(void) void ImageAsset::onTamlPostWrite(void)
@ -589,7 +588,7 @@ void ImageAsset::onTamlPostWrite(void)
return; return;
// Ensure the image-file is expanded. // Ensure the image-file is expanded.
mImageFile = getOwned() ? expandAssetFilePath(mImageFile) : mImageFile; mImageFile = expandAssetFilePath(mImageFile);
} }
const char* ImageAsset::getImageInfo() const char* ImageAsset::getImageInfo()

View file

@ -165,6 +165,7 @@ public:
void setImageFile(StringTableEntry pImageFile); void setImageFile(StringTableEntry pImageFile);
inline StringTableEntry getImageFile(void) const { return mImageFile; }; inline StringTableEntry getImageFile(void) const { return mImageFile; };
inline StringTableEntry getRelativeImageFile(void) const { return collapseAssetFilePath(mImageFile); };
void setGenMips(const bool pGenMips); void setGenMips(const bool pGenMips);
inline bool getGenMips(void) const { return mUseMips; }; inline bool getGenMips(void) const { return mUseMips; };

View file

@ -211,39 +211,21 @@ void MaterialAsset::initializeAsset()
void MaterialAsset::onAssetRefresh() void MaterialAsset::onAssetRefresh()
{ {
mScriptPath = getOwned() ? expandAssetFilePath(mScriptFile) : mScriptPath; // Ignore if not yet added to the sim.
if (!isProperlyAdded())
if (mMatDefinitionName == StringTable->EmptyString())
{
mLoadedState = Failed;
return; return;
}
if (Con::isScriptFile(mScriptPath)) // Call parent.
Parent::onAssetRefresh();
if (mMaterialDefinition)
{ {
//Since we're refreshing, we can assume that the file we're executing WILL have an existing definition. mMaterialDefinition->flush();
//But that definition, whatever it is, is the 'correct' one, so we enable the Replace Existing behavior mMaterialDefinition->reload();
//when the engine encounters a named object conflict.
String redefineBehaviorPrev = Con::getVariable("$Con::redefineBehavior");
Con::setVariable("$Con::redefineBehavior", "replaceExisting");
if (Con::executeFile(mScriptPath, false, false))
mLoadedState = ScriptLoaded;
else
mLoadedState = Failed;
//And now that we've executed, switch back to the prior behavior
Con::setVariable("$Con::redefineBehavior", redefineBehaviorPrev.c_str());
} }
else
load();
AssetManager::typeAssetDependsOnHash::Iterator assetDependenciesItr = mpOwningAssetManager->getDependedOnAssets()->find(mpAssetDefinition->mAssetId);
// Iterate all dependencies.
while (assetDependenciesItr != mpOwningAssetManager->getDependedOnAssets()->end() && assetDependenciesItr->key == mpAssetDefinition->mAssetId)
{ {
StringTableEntry assetId = assetDependenciesItr->value; load();
AssetBase* dependent = AssetDatabase.acquireAsset<AssetBase>(assetId);
dependent->refreshAsset();
} }
} }