Why custom C++ methods have target pin and they can't be empty?

hi, after making custom class based on any other class i can get access to my exposed method in blueprints, but every such method seems always have blue “target” pin and blame me with message

“This blueprint (self) is not a %s, therefore ‘@@’ must have a connection.”

if i leave it empty, i found that massage comes from engine source at

…\Engine\Source\Editor\KismetCompiler\Private\KismetCompiler.cpp

1091 line

if(PinType.IsEmpty())
{
ErrorMsg = FString::Printf(*LOCTEXT(“PinMustHaveConnection_NoType_Error”, “’@@’ must have a connection.”).ToString());
}
else
{
ErrorMsg = FString::Printf(*LOCTEXT(“PinMustHaveConnection_WrongClass_Error”, “This blueprint (self) is not a %s, therefore ‘@@’ must have a connection.”).ToString(), *PinType);
}

in this case i have few questions very confusing me:

  1. why and what for all (or not?) custom C++ methods have that target blue pin?
  2. can i avoid/trick that target pins with something the same without needs to search every time?
  3. if there isn’t easy ways, what common ways to avoid that target pin problem?

Try switching the method to static. Without seeing code i’m not completely aware of the real issue.

First question: do you know the basics of Object Oriented programming? If not, you’re going to need to learn it to use Blueprints very effectively, so go check into that.

If you do know OOP:
That pin is a pin for “self,” the object that the method you’re running needs to run on. If you know Object Oriented programming, you know that a method is a function of an object.

Now, if you’re running a method in Blueprints inside the class, it’s OK to leave this pin blank; Blueprints will assume that the object the method will run on is the class you’re in. If you try to run that same method from some other class, though, and you leave the pin blank, it will try to use the class you’re in, which isn’t the right class for that method.

Let’s say you have a class called “Apple,” and “Apple” has two methods, “CutUp” and “Eat.” In the definition of “Eat,” you create a “CutUp” node because you want to run that function since you have to cut the apple to eat it. The CutUp node’s “target” pin will be “self”, meaning the Apple you want to cut up is the same one as the Eat function you’re writing code for.

But let’s say you jump to your level blueprint, and you want to run Eat. Well, what Apple do you want to Eat? That pin is to specify which Apple’s Eat function you want to call.

in .h

#pragma once
#include “Engine/Blueprint.h”
#include “Steam_Bluprint_Functions.generated.h”

UCLASS()
class STEAM_TRAINING_API USteam_Bluprint_Functions : public UBlueprint
{
GENERATED_BODY()

UFUNCTION(BlueprintCallable, Category = "Steam")
bool CreateLobby();

};

in .cpp

#include “steam_training.h”
#include “Steam_Bluprint_Functions.h”
#include “steam_api.h”
#pragma comment(lib, “steam_api64.lib”)

bool USteam_Bluprint_Functions::CreateLobby()
{
//SteamAPICall_t hSteamAPICall = SteamMatchmaking()->RequestLobbyList();
SteamAPICall_t hSteamAPICall = SteamMatchmaking()->CreateLobby(k_ELobbyTypePublic
/* public lobby, anyone can find it */
, 4);
SteamFriends()->SetRichPresence(“status”, “Creating a lobby”);
return true;
}

in blueprint

i understand a little OOP since i learned basics of C++, but still think there should be a way to may a function that doesn’t depend on any exact instance of any object, for example

void my_stupid_function()
{
int result = 1 + 2;
}

why the hell such function for example must depend on any objects lol? of course it’s just stupid little example, but in my case most steam API function doesn’t depend on any unreal editor objects, like actors, game states, game rules and so on

friend knowing C++ very well explained to me, that method can avoid dependance on object with static declaration like

static void Myfunc() in .h file

but static keyword doesn’t mean function always must be outside any classes, in my .h i still keep

#pragma once
#include “Engine/Blueprint.h”
#include “Steam_Bluprint_Functions.generated.h”

UCLASS()
class STEAM_TRAINING_API USteam_Bluprint_Functions : public UBlueprint
{
GENERATED_BODY()

UFUNCTION(BlueprintCallable, Category = "Steam")
static bool CreateLobby();

};

but just static caused futher problem because i miss “public” keyword, this is what UE editor blueprint says then

so the fix would look like this in .h

#pragma once
#include “Engine/Blueprint.h”
#include “Steam_Bluprint_Functions.generated.h”

UCLASS()
class STEAM_TRAINING_API USteam_Bluprint_Functions : public UBlueprint
{
public:
GENERATED_BODY()

UFUNCTION(BlueprintCallable, Category = "Steam")
static bool CreateLobby();

};

now funcs compile fine in blueprints

OK, cool! So the code you’re writing is really functions, not methods – methods are a function that is bound to an object of some class. Regular functions are just functions with no class.

Like Stunt Thumper suggested, try making your methods static:

In normal C++, you would probably just make these regular functions and not put them in a class at all, but it looks like in UE4 all code you want to be blueprintable has to be in a class. Someone correct me if I’m wrong, though, I can’t find much documentation on it. Basically, by making the method static, you’re saying “hey, this function is defined in this class, but it doesn’t actually need an object of this class to run, it just runs on its own.” Then the pin should stop showing up because it won’t need an object to run on.

your’re right, but keeping functions inside class my friend use just for grouping, and i agree that’s better than leaving them without classes