ULevel Inheritance

Hi everyone,

I want to create a child class of the ULevel class contained in Unreal Engine source code (I’m testing on 4.27/5.0 and 5.1 codebases).

At first, creating a class like

UCLASS()
class DEMOPROJECT_API UMyLevel : public ULevel

Generate a lot of linking errors (28) like :
error LNK2001: unresolved external symbol "public: virtual void __cdecl ULevel::Serialize(class FArchive &)" (?Serialize@ULevel@@UEAAXAEAVFArchive@@@Z)

I read on another forum post that it’s because of the minimalApi parameters in the UCLASS macro of ULevel. I removed it and added ENGINE_API to the class as I read on another forum post.

UCLASS() 
class ENGINE_API ULevel : public UObject, public IInterface_AssetUserData, public ITextureStreamingContainer

With that in class, I got an error messages telling me that members of the ULevel class with ENGINE_API cannot have that ENGINE_API macro if the class itself already has it.
Error C2487 'Serialize': member of dll interface class may not be declared with dll interface

I removed all ENGINE_API for all the methods that are contained in the ULevel class but I still get three errors :

error C2487: 'GetPrivateStaticClass': member of dll interface class may not be declared with dll interface
error C2487: 'Serialize': member of dll interface class may not be declared with dll interface
error C2487: 'ULevel::{ctor}': member of dll interface class may not be declared with dll interface

From what I see, these methods seems to have generated by the GENERATED_BODY macro and they seems to have ENGINE_API.

My questions are :

  1. Is there a way to remove those ENGINE_API from the generated code by the generated body macro (parameters/config…) ?
  2. Is it possible / allowed to inherit from ULevel ? If so, is there a simpler way to do it ?

Thanks,

I don’t think you’re actually supposed to subclass ULevel. The best way to extend a ULevels functionality is to create an AActor subclass and spawn it into the level. There is an actor subclass you can derive from called AInfo that is for actors that don’t have any sensible position in the world (like GameModes for example).

Also worth taking a look at is UWorldSubsystem. They are better for where you want some functionality in every world of your game.