Access static variable in a different class in C++/Unreal Engine 4

Hi everyone!

I have a static variable declared in a header file and initialized in the corresponding cpp file. What I’m trying to do is accessing that variable from another cpp file. This is the code:

AkOcclusionObstructionService.h

class AkOcclusionObstructionService
{
public:

    static float OcclusionFadeRate;
    ...
}

AkOcclusionObstructionService.cpp

...
float AkOcclusionObstructionService::OcclusionFadeRate = 3.0f;
...

MyBlueprintFunctionLibrary.cpp

#include "MyBlueprintFunctionLibrary.h"
#include "AkOcclusionObstructionService.h"

void UMyBlueprintFunctionLibrary::ChangeWwiseFadeRate(float rate)
{
    AkOcclusionObstructionService::OcclusionFadeRate = rate;
}

When I try to build Visual Studio gives me this error:

LNK2001 unresolved external symbol “public: static float AkOcclusionObstructionService::OcclusionFadeRate” (?OcclusionFadeRate@AkOcclusionObstructionService@@2MA)”.

It looks like MyBlueprintFunctionLibrary can’t see the OcclusionFadeRate variable in the AkOcclusionObstructionService cpp file.

Additional Linking/building info:

To make the “AkOcclusionObstructionService.h” file visible to the “MyBlueprintFunctionLibrary.cpp” file we had to add something to the “TestFadeRateWwise2.build.cs” (TestFadeRateWwise2 is the project name). Specifically we had to add “AKAUDIO” to this line:

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "AKAUDIO" });

That’s the only “non standard” thing I did.

Anyone has an idea of what is happening?

Thanks in advance!

It looks like you’re not exporting things correctly. You have the PublicDependencyModuleNames part, but UE4 doesn’t know what it should get from AKAUDIO.

Try this and let me know how it goes.

Have you ever resoleved this Problem? I have the same question.