Is there a way to tell the cooker not to load the full import map of an object?

I have a custom UObject that generates two UMaterials under the hood. Each UMaterial can reference a different set of UTextures.

Both Materials need to be available in the editor (and they are UProperties). However at cook time, I would like to make a decision in code as to which one to cook. The other one and its references should be discarded and never cooked. Is there a way to do this?

I have tried in my custom UObject::Serialize() to check for Ar.IsCooking() and null out the reference to the Material that will not be needed. This does remove the reference and the target platform doesn’t load the unused Material nor its textures. However, I see that the UTextures that the unused Material referenced are all being cooked even though they will not be used. Is there a mechanism to stop this? I see that the cooker loads everything in the ImportMap before an object’s Serialize is called.

Thanks for your help.

Hi,

The short answer is no. However you could try checking NeedsLoadForServer() and NeedsLoadForClient() functions and define them on objects that you don’t want to be cooked. However, what’s been loaded, will always be cooked (well, with the exception that if the package consists only of objects that have those two functions defined to return false, it will not be saved in the cooked folder).

Hi,

We think this post contains useful information which we would like to share with our public UE4 community. With your approval, we would like to make a copy of this post on the public AnswerHub which includes the discussion but strips out your username and company name. Please let us know if you are okay with this.

Thanks!

I assume that wrapping the property with WITH_EDITORONLY_DATA will not help the situation (it will still be loaded during cooking).

How much of a change would it be to add a uproperty specifier like “nocook” to remove data from cooked builds?

I’m not a huge fan of this. Adds complexity to already overcomplicated system and can cause potential issues when something depends on the asset on load.

Note that if you override NeedsLoadForServer and NeedsLoadForClient on the object you load and don’t want to be cooked and it’s the only object in your asset package (except UMetaData etc) then the package will be flagged as contatining editor data only and will not be saved. In other words, if all UObjects within a package have NeedsLoadForServer and NeedsLoadForClient overriden to return false, the package will not be cooked.

After looking at the cooker, I have to agree that a property specifier is not the way to go.

Is there any concern about this for other classes? For instance, MaterialInstances that override all of the ParentMaterial’s texture parameters. When cooking the Material Instance, it brings in all of the MaterialExpressions in the ParentMaterial and loads/cooks them. The Texture Expressions then bring in textures that will never be used.

Another example is, Editor Icons (such as S_DecalActorIcon). These won’t be used by the game, but are cooked.

Hi Ian,

We’re looking at cleaning up those and also introducing ‘Never Cook’ folders. We’re also considering making properties inside WITH_EDITORONLY_DATA behave the way you originally requested. Eta is probably sometime around 4.10 release.

Hi Ben. Sure, that will be fine.