How to remove the "Target [self]" input when making BlueprintCallable functions? [SOLVED]

Hello, essentially what I wish to do is this; I wish to create two BlueprintCallable functions, one to take input and return a Tile object, the other to take a Tile object and return output. (Basically like make/break vectors) Because I couldn’t find a way of creating a class that would act as a simple data container by normal means, I am using an Actor as the parent class. The issue is the

, because I’m using these functions within the level blueprint, it’s giving me the error

My first function, MakeTile is meant to take in two int32s and a bool as input, but instead it takes those and
“Target [self]” So am I going about this the wrong way, or is there just some sort of way of removing “Target [self]” that I’m not aware of? I’m using two classes, a BlueprintFunctionLibrary called TileLib and an Actor called Tile. (I have tried storing the functions within Tile too, same result)

–Make Tile in BP

–Break Tile in BP

–Tile .h

–Tile.cpp

–TileLib.h

^ It shows an error but compiles completely fine, so I don’t know why.

–TileLib.cpp

I also have no idea why the input in BP is labeled as “T” instead of “Tile To Break”

Thanks for reading. I’ve probably made some idiotic mistake, but for the life of me I can’t figure it out.

you should put “static” in front of your blueprint function library declarations.

blueprint function library methods are expected to be static functions, that’s what allows them to be used anywhere.

3 Likes

So, that worked perfectly to remove the “Target [self]” but now I have a new issue. Whenever I run it, within the MakeTile BP function, it throws an error during run-time and crashes ue4. The stacktrace led me to this line

http://i.imgur.com/iLLlXec.png

line 24 of tile.cpp, but after reproducing it the stacktrace changed, I don’t have the previous one but here is the new one

http://i.imgur.com/Yw8XfTm.png

I can’t follow the stacktrace, I’ve searched a few things about it but can’t seem to find any results (After searching for only 30 mins, I’m going to keep searching, but do you know why this is?)

you should check if TileToBreak is valid before getting things from it.

is there any reason x and y are not Uproperties?

I haven’t used the return value, it crashes just within MakeTile, before it reached BreakTile.

Okay, after doing some tracking down and testing, it only crashes when this line is uncommented

http://i.imgur.com/QSM2M2k.png

(The NewObject() line) Through searches, this seems to be the way to create new objects. Is there another way? I shall consult Uncle Google for now.

EDIT: I should note that

http://i.imgur.com/5nrHJhT.png

doesn’t work either.

There was no reason they were not UProperties, they are now. Doesn’t change the issue I currently have with instantiating a new ATile for returning, but thanks for pointing that out.

It just occurred to me! This is an ACTOR I’m using, it doesn’t make sense to instantiate it, I need to spawn it in. The only issue then is I don’t actually want the actor in the physical world, so is there an alternative class I should use?

it seems like this is just a data holder so far, why not use a struct?

USTRUCT seems like a perfect solution, I wouldn’t even need TileLib. There’s an article saying this

http://i.imgur.com/VLH2NX7.png

I’ve replicated it by doing this

http://i.imgur.com/u6q6Rl8.png

and removing the TileLib methods. The only issue is that the Auto Make/Breaks that should be there, aren’t.

http://i.imgur.com/hGCRu21.png

Is this the right way to be using USTRUCTs? I’m following the syntax exactly from what I can tell. Also, this is the page I was talking about A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums

EDIT: I should note that in the pic of me searching for it, it was context sensitive on, but I have tried with it off.

use
USTRUCT(BlueprintType)

so you can use the struct as a variable in blueprint.

and maybe inherit from FTableRowBase, if you want to use your struct with spread sheets:

USTRUCT(BlueprintType)
struct FRPGStats : public FTableRowBase
{
	GENERATED_USTRUCT_BODY()


	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "RPG")
		int32 HP;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "RPG")
		int32 Attack;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "RPG")
		int32 Defense;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "RPG")
		int32 Speed;

};

Just saw that by googling some more, and finally… Everything WORKS! Thank you so much, this has been bugging me for a long time now.