We met an issue with memory usage.We found a lot of loaded textures’ usage count is 0 from MemReport, which means these textures are not used in our game. I debug this issue and found the reason is UE constructed an object when used CastTo (for example cast to our derived ATestCharacter) derived classes even if we just put an CastTo node in blueprint. Could you tell me how to avoid this situation? We only want to load these textures we are used in game.
If the CDO of the class you’re inheriting references a texture, that texture will be loaded along with the entire CDO when the class is casted to. There are a couple of ways you can avoid loading unneeded textures.
If possible, you could set the texture reference in the inherited classes rather than in the base. That would avoid it being loaded in child classes that don’t need it.
Another option would be to replace the texture pointer with a TAssetPtr. That should cause the texture to only be loaded when needed.
Thank you very much, Cody. This is very helpful.