I can’t seem to call the “StaticClass” method on classes declared in other modules.
In IndependentModule, I declare ATestActor and ATestActor2:
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "TestClass.generated.h"
UCLASS()
class INDEPENDENTMODULE_API ATestActor : public AActor{
GENERATED_BODY()
public:
};
UCLASS()
class INDEPENDENTMODULE_API ATestActor2 : public AActor {
GENERATED_BODY()
public:
};
In DependentModule, I add “IndependentModule” to the Public/PrivateDependency list.
I then try to access the “StaticClass” methods of each class:
#include "IndependentModule/Public/TestClass.h"
void UDependentComponent::TestFunction()
{
UClass* Class = AActor::StaticClass();
UClass* Class2 = ATestActor::StaticClass();
UClass* Class3 = ATestActor2::StaticClass();
}
I get the following error: unresolved external symbol “__declspec(dllimport) private: static class UClass * __cdecl ATestActor2::GetPrivateStaticClass(void)” (_imp?GetPrivateStaticClass@ATestActor2@@CAPEAVUClass@@anonymous_user_9674a66c) referenced in function “public: void __cdecl UDependentComponent::TestFunction(void)” (?TestFunction@UDependentComponent@@QEAAXXZ)
I don’t understand why this is failing on ATestActor2, but working on ATestActor. Additionally, if I change ATestActor to any other name, it fails. I have exposed the classes via the _API. The module is added to the appropriate Dependency list(s). What am I missing?
UPDATE: Several months later, I ran into a similar problem. After some testing in different contexts, the following conclusions are apparent:
- Adding SomeNewMethod to a class in IndependentModule and implementing that method in the same header file creates no linker issues. DependentModule can call the method with no problems.
- Adding SomeNewMethod to a class in IndependentModule and implementing that method in the appropriate source file creates linker issues. DependentModule cannot call the method. The only fix is to “Rebuild Solution/Project” (or delete Intermediate/Binaries, as detailed in comments), which takes much longer than a normal iterative “Build”.
Hence, the follow-up question is why? Is this aberrant behavior, caused by some missed lines/files somewhere? Otherwise, if this is expected behavior when linking updated game modules, I would like to know that, so that I can structure development to minimize lengthy Rebuilds.