Download

Cannot save my manually created resources, bad naming?

I create materials like:
UnrealMaterial = NewObject<UMaterial>(Package, *FixedMaterialName, RF_Public);

and all seems to be ok but they fail on being saved, I noticed that if I click ctrl + c it copies this:
Material’/Game/Materials/.Redishmat’

being “Redishmat” my material name

if I duplicate the material I can save it properly but ctrl + c says:
Material’/Game/Materials/Redishmat.Redishmat’

Any idea on this? Thank you in advance

It looks like your Package variable is invalid, since it’s the package that precedes the ‘.’ in the asset path. How have you obtained/created the package?

I created the package too but I don’t think that this should be the problem since the materials are created properly in their package but I cannot save them


FString myPackageMatName	= PackageTools::SanitizePackageName(InParent->GetOutermost()->GetName() + _T("/Materials/"));
PackageMat = CreatePackage(nullptr, myPackageMatName.GetCharArray().GetData());

but also tried with _T("/Materials") without the slash but I had no luck neither.

You were right! I had to create a ‘sub-package’ for my material, thats all!

That doesn’t look right, since you’re appending a subpath onto a package name rather than onto a path. Try constructing it something like this:



FPackageName::GetLongPackagePath(InParent->GetOutermost()->GetName()) / _T("Materials") / MaterialName


FString overloads the / operator to make it easier to concatenate paths without worrying about separators.
GetLongPackagePath will take a full package path and cut off the name from the end to give you the location of the package.

EDIT: Guess I took too long to write!

Ufff materials are not saved yet, they seems to be (the asterisks are gone when clicking on save) but reopening the project they are not more there. If I edit it like moving a node or whatever and click on save they are saved properly!