Allocate FStaticMeshRenderData

I would like a simple Actor to allocate a FStaticMeshRenderData instance on the heap.

I have included “StaticMeshResources.h” and the code compiles - all good so far. But I get a link error:

Error	2	error LNK2019: unresolved external symbol "public: __cdecl FStaticMeshRenderData::FStaticMeshRenderData(void)" (??0FStaticMeshRenderData@@QEAA@XZ) referenced in function "public: __cdecl AMyActor::AMyActor(void)" (??0AMyActor@@QEAA@XZ)	D:\Develop\C++\Unreal Projects\MeshLoader\Intermediate\ProjectFiles\MyActor.cpp.obj	MeshLoader

Apparently the constructor cannot be found.

I was under the impression that I could modify the *.Build.cs script to make sure that the linker finds the constructor (located in Source\Runtime\Engine\Private\StaticMesh.cpp).

I did the following change:

    PrivateIncludePaths.AddRange(new string[] { "Runtime/Engine/Private" });
	PrivateDependencyModuleNames.AddRange(new string[] { "Engine" });

Could somebody please shed some light on what I am doing wrong here?

Here is some test code for the actor:

#include "MeshLoader.h"
#include "MyActor.h"
#include "StaticMeshResources.h"
                    
                    
AMyActor::AMyActor()
{
            PrimaryActorTick.bCanEverTick = true;
                    
       	 UStaticMesh* mesh = NewObject<UStaticMesh>();
            FStaticMeshRenderData* renderData = new FStaticMeshRenderData();
}

Thanks,
J

It’s complaining because that constructor isn’t actually exposed outside of the engine library (i.e. there’s no ENGINE_API declaration in front of that class, only on a handful of its methods). I did a quick search and it looks like all the code that actually handles that structure is within the Engine lib, everywhere else just uses a reference to hold on to already constructed data.

The fix would be to add ENGINE_API in front of the constructor declaration so it’s properly exported, but that may end up spider webbing out though. What is the root problem you are trying to solve? Maybe you should rethink your solution.

Thanks for the info! I missed that information when reading the manual.

Anyway, in the area where this is mentioned there is also information concerning “monolithic” mode and “modular” mode"

https://docs.unrealengine.com/latest/INT/Programming/Modules/API/index.html

"The easiest way to think about these specifiers is that they’re used to tag functions, classes or data as “public” to your module’s DLL file. If you mark a function in the Engine module as ENGINE_API, then any module that imports Engine can access that function directly.

These are only used when compiling the engine in “modular” mode (DLL files on desktop platforms). The opposite is what we call “monolithic” mode, which globs all code together in a single executable file."

So it seems to me that one solution might be to build the project in “monolithic” mode or as you mentioned declare the constructor for FStaticMeshRenderData as public (by using ENGINE_API). I will look into those “solutions” next.

**The scenario I am trying to solve is basically to load/create unreal compatible meshes from my own file format when a game is running. If anybody can see a better way to attack this problem please let me know. **

Btw, I have looked at the fbx importer but it has dependencies to code in the editor like FRawMesh (that I guess is not available in a running game).

Thanks,
J

Hi J. I’m now working on creating StaticMesh using runtime api. Any progress on this?