0
\$\begingroup\$

I've got a C++ component and I want to have function which will be implemented in Blueprint like this:

UFUNCTION(BlueprintImplementableEvent)
Stats& GetStats();

But this doesn't compile, I get the following error:

overload function differs only by return type from

and Unreal generates function inside .gen.cpp looking like this:

Stats Component::GetStats()
{
// ...
}

Stats is USTRUCT

\$\endgroup\$
1
  • \$\begingroup\$ I could be wrong but it looks like Unreal is expecting a return value (whatever stats you're getting from GetStats) and you're not giving it one in the UFUNCTION call. \$\endgroup\$
    – Stephen
    Sep 13, 2018 at 15:13

1 Answer 1

1
\$\begingroup\$
//////////////////////////////////////////////
//By reference
//////////////////////////////////////////////
//.h
UFUNCTION(BlueprintCallable)
    void GetStats(const FStats& stats);

//.cpp
void YOURCLASS::GetStats(const FStats& stats)
{
    stats = FStats();
}

//////////////////////////////////////////////
//Copy
//////////////////////////////////////////////
//.h
UFUNCTION(BlueprintCallable)
    FStats GetStats();

//.cpp
FStats YOURCLASS::GetStats()
{
    return FStats();
}
\$\endgroup\$
2
  • \$\begingroup\$ No, instance of Stats is created in blueprint and I need to return it from blueprint to c++. \$\endgroup\$
    – devalone
    Sep 13, 2018 at 16:54
  • \$\begingroup\$ @devalone then use the reference method. \$\endgroup\$
    – Rotem
    Dec 27, 2019 at 3:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .