[4.7.6] - Material Reference 'Not Found'?

Hey Guys,

I have an issue where I have a Material Instance created in a project I am working on and when I reference it through C++ to store it as a default for a custom Actor, it tells me upon Engine load that the reference to the asset doesn’t exist however it does and is using the same reference path that I am getting when clicking “Copy Reference”.

Let me know how you’d like me to proceed and hope you and the team are having a great day!


I also fixed this one as well. I created a MaterialInstance from the original one and it worked. I tried this before so I am not sure why it passed through but as far as now is concerned, it’s no longer an issue.


UPDATE: This works now in the editor but fails when running a Staging Build. Is there any reason this would fail to find the asset outside of the editor?

Hi MC -

Depending on what your Custom Actor is doing are you certain that you do not need a Dyanmic Material Instance instead of a Material Instance Constant (the MIs created in the Content Browser)? Particularly if you have some parameter changing on the Actor at Runtime you would be better off making the Master Material in Teh COntent Browser and then create a Dynamic Material Instance in code using the Master Material as reference.

Hopefully this helps you out

Eric Ketchum

Hey Eric,

In this case I can’t use a MaterialInstanceConstant :frowning:

I have a material applied to a game that does unit management. The material changes color right now depending on if a given unit is selected. The thing is I don’t use a property anymore and am doing the dynamic material like so…

In my class header I use this function to get the material back after it’s been applied…

// The link below is someone having the exact same issue and how they solved it...
// https://forums.unrealengine.com/showthread.php?10785-UPROPERTY()-UMaterialInstanceDynamic*-Prevents-maps-and-blueprints-from-saving
	FORCEINLINE UMaterialInstanceDynamic* GetMaterialInstanceDynamic() const
		return Cast<UMaterialInstanceDynamic>(Mesh->GetMaterial(0));

This is how I am creating the material and applying it…

// Create our DynamicMaterialInstance
	auto MaterialInstance = UMaterialInstanceDynamic::Create(Material, NULL);
	if (UGameExtensions::IsValid(MaterialInstance)) Mesh->SetMaterial(0, MaterialInstance);

However, I believe what’s causing the issue is having this in my OnConstruction override…

int32 VariantCount = CrystalVariants.Num();
	if (VariantCount > 0)
		if (Randomize)
			int8 VariantIndex = FMath::RandRange(0, VariantCount - 1);
			Mesh->SetMaterial(0, Material);
			Mesh->SetMaterial(0, Material);

I tried doing this in the constructor but the CrystalVariants variable is not seeing the default data from the BP at that point until it gets to the OnConstruction function.

Hey Eric,

I wanted to quickly check in to see if you had any new info on the matter?

I’m wondering if using 'ConstructorHelpers::FObjectFinderOptional<>(…) is only valid if you are in the editor. I’m guessing no since I don’t have a problem w/ any of my other assets. My intention is to take the hard coded defaults away but it would be nice if I could reference a starting material to be the default for a BP to start with.

Thanks and hope you are having a great week!

Hey MC -

I know it has to be in the constructor but beyond that it should be valid as you expect it (in both). We have run some test trying to replicate your issue here and haven’t been able to do it. Can you upload a sample project with the source code from above causing the issue so we can take a look at it?

Thank You

Eric Ketchum

Thanks for checking this out Eric. You guys are awesome. I wanted to let you know that after doing some testing and re-targeting against the source (4.7.6) and then re-targeting back for some testing, it happened to resolve itself w/out any changes. I didn’t see it fail for any of my other hard coded references for any other asset but maybe if I had did a Clean/Re-Build then it would’ve fixed it. Maybe some file in Intermediate that never thought it needed to re-build itself maybe.

But glad it worked :slight_smile: but I unfortunately can’t test any methods to resolve this out but I’ll let you know if it becomes an issue again. Most of these references are going to be overridden from BPs but some of the base classes need a base asset to default to.

Oh and as a heads up if this helps… I would reference the assets like so…

struct FConstructorStatics
   ConstructorHelpers::FObjectFinderOptional<UMaterialInstance> MI;
   FConstructorStatics() : MI(TEXT("MaterialInstanceConstant'/Game/Core/Materials/MI_Shard.MI_Shard'")
static FConstructorStatics ConstructorStatics;

if (UGameExtensions::IsValid(UMaterialInstance* MI_Asset = ConstructorStatics.MI.Get()))
   // Do Something...