How to add custom classes created in C++ to a list through Blueprint

Hi! So I’m currently trying to create a system where I can select items that I created and add them to a list in a Blueprint. Basically, I have a few different “actions” created in C++ all inheriting from the same class, and the goal is that for each actor in the scene you can basically pick and choose which of these “actions” will be used. However as I’m relatively new to Unreal’s use of C++, I don’t really know how I’d be able to do this. My only guess would be by storing a list somewhere else and then adding those individual elements to a separate list or something like that. Any advice would be greatly appreciated, thanks!

you can just add your items to list in c++ and expose it to blueprint by using BlueprintReadWrite(for read and write both) or BlueprintReadOnly(for reading data only) property specifiers
Ex:

UPROPERTY(BlueprintReadWrite)
TArray<AItem*> ItemsList;

Blockquote

Thanks for shearing i will check it.

Important thing to note is that your C++ class needs to have the BlueprintType specifier to be able to be used in blueprint

Just to follow up on this, I ended up using TSubclassOf and then getting the default object of that class as they aren’t intended to be changed at all. No idea if this will cause issues but it works for now.

Depending on what you do it might be fine
If the functions that you call on the CDOs do not modify the CDO, it is fine, and is something that is used commonly in the engine
If you want to have different states per object though, what you can do instead is add the EditInLineNew specifier to your class and the Instanced specifier to your array
That way you can add objects of your class and it will create an object inline, which you can then modify as you want, in editor time and runtime

They seemed to be causing issues for some reason so I swapped them out, now I just create them as new objects. I think maybe it had something to do with trying to delete them, as that seemed to cause huge issues.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.