C++: Deriving from UStaticMesh gives compiler error

I want to create a Menger sponge fractal mesh in C++ by deriving from UStaticMesh.

I used the wizard in UE4 editor to create a class that derives from UStaticMesh but I receive the following compile error without modifying anything after the automatic class generation:

1>E:\UE4\Unreal Engine\4.4\Engine\Source\Runtime\Core\Public\Templates\ScopedPointer.h(36): error C2514: 'FStaticMeshRenderData' : class has no constructors
1>          E:\UE4\Unreal Engine\4.4\Engine\Source\Runtime\Engine\Classes\Engine/StaticMesh.h(320) : see declaration of 'FStaticMeshRenderData'
1>          E:\UE4\Unreal Engine\4.4\Engine\Source\Runtime\Core\Public\Templates\ScopedPointer.h(33) : while compiling class template member function 'TScopedPointer<FStaticMeshRenderData>::TScopedPointer(const TScopedPointer<FStaticMeshRenderData> &)'
1>          c:\users\l\documents\unreal projects\mengersponge\source\mengersponge\MengerSpongeStaticMesh.h(19) : see reference to function template instantiation 'TScopedPointer<FStaticMeshRenderData>::TScopedPointer(const TScopedPointer<FStaticMeshRenderData> &)' being compiled
1>          E:\UE4\Unreal Engine\4.4\Engine\Source\Runtime\Engine\Classes\Engine/StaticMesh.h(320) : see reference to class template instantiation 'TScopedPointer<FStaticMeshRenderData>' being compiled

I have then searched and found the relevant include to be “StaticMeshResources.h” that is obviously missing, but this causes another compiler error to be generated:

1>E:\UE4\Unreal Engine\4.4\Engine\Source\Runtime\Engine\Public\StaticMeshResources.h(711): error C2248: 'FColorVertexBuffer::FColorVertexBuffer' : cannot access private member declared in class 'FColorVertexBuffer'
1>          e:\ue4\unreal engine\4.4\engine\source\runtime\engine\public\Components.h(164) : see declaration of 'FColorVertexBuffer::FColorVertexBuffer'
1>          e:\ue4\unreal engine\4.4\engine\source\runtime\engine\public\Components.h(29) : see declaration of 'FColorVertexBuffer'
1>          This diagnostic occurred in the compiler generated function 'FStaticMeshLODResources::FStaticMeshLODResources(const FStaticMeshLODResources &)'

Any tips are welcome.

I still use UE 4.4.3 though.

I have now tested this against 4.5.1, but the error is still exists.

Any hints?

Hi Lyve,

I think it is not good idea to do that. First of all you have error cause API export/import macro, in this case compiler generates copy constructor (but it is not allowed in FColorVertexBuffer).

I am not sure that UStaticMesh can solve your problem with Menger Sponge. In any way if you really want to do that you should declare this class in Engine (to avoid unresolved external references) and delete export/import macro (UStaticMesh is not fully exported/imported, only some function of this class).

Alternative way to create Menger Sponge can be procedural mesh generation. Check out this A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums

Best regards,

The link you’ve pointed out, this is the current way I’m doing this as can bee seen here Screenshot

But there are some problems left, as far as I know the example code you posted uses dynamic rendering, I’ll have to figure out how to put my mesh into the static rendering path, this should result in better performance.

Additionally, the UStaticMesh method would’ve the advantage that I could switch between Movable and Static in the UE4 Editor, at the moment this switch is not possible

Hi Lyve,

Mobility it is simple option that you can change in component by SetMobility. If you want to see this option in editor you should add ShowCategories=(Mobility) to UCLASS of UGeneratedMeshComponent.

Yes, you are right about dynamic rendering. We will check for solution.

Best regards,