Reference a blueprint in C++ (Connect Pin Error)


		/** Please add a variable description */
		UPROPERTY(BlueprintReadWrite, EditAnywhere, meta=(DisplayName="Affliction"))
		TSubclassOf<class UObject> AfflictionClass;

I have a C++ Struct, that I’m trying to add a complex blueprint reference to (to get it to work while i convert the entire thing to C++)

So, I’m trying to use the BreakStruct node to convert it to blueprint but get this.

I’ve tried referancing the parent (Object Class), among a few other trials, but nothing seems to get it to connect.

Does anyone know how to get through this?

The problem here is that your struct is using UObject as AfflictionClass, while the method GetEffect takes BPAfflictionClass and not UObject.

Easiest way to explain it is “an apple is a fruit, but a fruit is not an apple”, an AfflictionClass can be a UObject, but not the other way around. You should create a new c++ class “UAfflicationClass” and make that blueprint BPAfflicationClass inherit from it (by setting the parent class on the editor panel). In your c++ struct instead of using UObject for the property you use UAfflicationClass. Update the variables / parameters to accept that c++ class as input.

1 Like

Thanks for the reply Roy! It’s making more sense on what was going wrong, I’m a step closer (I think) but the last bit both in blueprints and my mind isn’t connecting.

So the updated structure is now:

		/** Please add a variable description */
		UPROPERTY(BlueprintReadWrite, EditAnywhere, meta=(DisplayName="Affliction"))
		TSubclassOf<UAfflictionLink> AfflictionLink;

Which is beginning to make sense. Knowing that C++ can’t communicate with blueprints, having this file that they both can reference is a dot connected. But the I’m really unsure what I’m missing to get this to connect.

Here’s the new C++ parent class.

#pragma once

#include "CoreMinimal.h"
#include "AfflictionLink.generated.h"

UCLASS( Blueprintable)
class XXX_API UAfflictionLink : public UObject

Here’s where the blueprint stands…

And where the BP is parented

Thanks for the gander.

What remains is that the data type of parameter Affliction on the method GetAffliction should be updated to be the c++ class you made, else you have the same problem as I described with the UObject.

You should probably also add the specifier “BlueprintType” to the UCLASS:

Class Specifiers | Unreal Engine 4.27 Documentation

Thank you so very much Roy. I was not getting the connection, that I could replace the blueprint reference to my CPP for the input.

Here was my final issue.

1 Like

Dang it. I thought I understood. But I still can’t seem to get the data from the struct. In my head I thought it was pulling from the parent struct and it built the connections from there. but getting the functions out of the original BP is still an issue. I can call them from BP itself, but when I used the LINK it doesn’t have them. I assume it’s because I don’t have them defined in my AfflictionLink.h, but my worry is that if I put them in the link, the names will show up and connect just fine but the functionality won’t be there.


Sorry, thought I understood =/

Update: I did go ahead and put it into the AfflictionLink.H It does connect with the gameplay tags.

	/** Removes Affliction */
	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category="Application", meta=(MultiLine="true"))
	FGameplayTagContainer RemoveAfflictionWithTags;


But I’m wary that this is best practice?
Thanks for the help, I should be done with construction in the next few days and will will remember to post back!

If you wish to call any of the methods, or access data through that c++ class then you must first port what you implemented in Blueprint to c++. This is the correct way to do it though, just port it all one by one.

I think you are also mixing up something else here. You are accessing data from the class default on that image. I think you might want to access data from an object instance instead? If you don’t know the difference between a class and an instance it is important to look for a tutorial about that asap.

Thanks so much for support Roy, I’ll go brush up on object instancing. Converting a project to C++ from BP has been an immense learning experience. I appreciate your help!

1 Like

This shows the difference quite well:

In Blueprint a class pin is purple and an instance is a blue pin.