Adrian Rozlach
Adrian Rozlach

Reputation: 51

UActorComponent derived class in plugin is not reacting for function calls

So I have a little problem with creating project plugin in Unreal Engine for (4.15). So let's break it down. 1.I've created MyClass that is derived from UActor Component and has also this line:

UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent))

2.I've added that component to my GameMode. 3.Then I'm trying to call any function from inside the class by Get GameMode then casting to MyGameMode and getting MyClassComponent. 4.When I'm trying to call function nothing happens at all.

I was trying to debug it but it never goes in function body but prints before function and after works perfectly fine. I also must say that when functions are compiled straight into project they work 100% fine!

This is sample of how do I declare my functions:

UFUNCTION(BlueprintCallable, Category = "MyClass|Test")
        void TestFunction();

void UMyClass::TestFunction()
{
    GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Red, "hello there");
}

If there is any more information required that I'm not aware of please let me know.

MyClass declaration

UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) 
class UMyClass : public UActorComponent 
{ 
GENERATED_BODY() 
public: 
UFUNCTION(BlueprintCallable, Category = "MyClass|Test") 
void TestFunction(); 
};

Upvotes: 0

Views: 373

Answers (1)

Rotem
Rotem

Reputation: 21927

Any classes that need to be consumed publicly need to have their symbols exported.

In UE plugins this is achieved with the YOURPLUGIN_API specifier, where YOURPLUGIN is the name of the plugin.

This in turn is defined as __declspec(dllexport) when exporting and __declspec(dllimport) when consuming the plugin.

So your class definition should look like:

UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) 
class MYPLUGIN_API UMyClass : public UActorComponent 
{
    ...
}

Upvotes: 1

Related Questions