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
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:
why and what for all (or not?) custom C++ methods have that target blue pin?
can i avoid/trick that target pins with something the same without needs to search every time?
if there isn’t easy ways, what common ways to avoid that target pin problem?
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.
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
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.