Trouble calling blueprints in C++

Using 4.4.3

I have a blueprint for an item database called MyItemDatabase.
The referrence to the blueprint is as follows:

Blueprint'/Game/Blueprints/MyItemDatabase.MyItemDatabase'

I tried to initiate this blueprint in my GameMode.cpp using the following:

static ConstructorHelpers::FObjectFinder<UClass> ItemDB(TEXT("Blueprint'/Game/Blueprints/MyItemDatabase.MyItemDatabase'"));

This compiles perfectly fine, but whenever I begin initializing the editor I get an error stating that it cannot find the blueprint. I think this is because my reference starts with “Blueprint” and will not work with UClass.

I have tried instead using UBlueprint instead of UClass as I saw it in several snippets posted here, but then I fail to compile due to the following error:

Error	6	error C2664: 'void ConstructorHelpers::ValidateObject(UObject *,const FString &,const TCHAR *)' : cannot convert argument 1 from 'UBlueprint *' to 'UObject *'	

This error led me to try to use UObject instead and now it works perfectly fine, but It looks like I cannot find any other examples of someone using UObject with FObjectFinder and now I’m confused if I’m doing something i’m not.

This leads me to several questions that I would love to have answered:

  1. Why do so many snippets I see have blueprint references that begin with “Class” instead of “Blueprint”?
  2. How could I even create/edit a blueprint that has a reference that does not start with “Blueprint”
  3. Why am I have such a hard time getting UBlueprint to work when I see other people able to use it in their tutorials/snippets?
  4. Should I be using UObject? If so then why can I find no examples of others using this?

Yes. Objectfinder looks for UObjects. To get a class from that found object you should use code like this:

if (ItemDB.Object != NULL)
{
    MyItems = (UClass*)ItemDB.Object->GeneratedClass;
}

Hello TimGS,
Thanks for the response. While it is not really an answer to any of my questions in my post, it is an example of the next step of the process, and also the answer to a question I had yet to ask, but have been working on, so I appreciate the assistance.

One problem:

When I try to compile that line I get the following error:

Error	7	error C2039: 'GeneratedClass' : is not a member of 'UObject'	

I had already tried this before I posted my original question which led me to wonder if I should even be using UObject in the first place.

Ultimately I want to be able to do something like this:

MyItems = ItemDB->GetDefaultObject<AItemDatabase>();

But having trouble getting a class from the object.

Oh, maybe I got you wrong.

Error 6 error C2664: ‘void
ConstructorHelpers::ValidateObject(UObject
*,const FString &,const TCHAR *)’ : cannot convert argument 1 from
‘UBlueprint *’ to ‘UObject *’

This one is really strange. Seems like they changed UObject class so this doesn’t work any more.

This code does though (and I don’t get errors about blueprint not found):

ConstructorHelpers::FObjectFinder<UObject> BlueprintObj(TEXT("Blueprint'/Game/Blueprints/MyTestActor.MyTestActor'"));

UBlueprint* MyBlueprint = NULL;

if (BlueprintObj.Succeeded()) {
	MyBlueprint = (UBlueprint*)BlueprintObj.Object;
}

So, here’s you answer for 4. Seems like we have to use UObjects now in finder.

  1. That’s probably because those snippets used blueprints as classes which blueprints actually are, they just derive from their base class and extend that with visual scripting logic made by dev.
  2. Seems like I don’t quite understand this question. If you want reference of blueprint I gave you working code above then. I hope that will help you with 3. too

Hello TimGS,
That did the trick! As always thanks for your time and assistance.

Regarding the following:

Seems like I don't quite understand this question. If you want reference of blueprint I gave you working code above then. I hope that will help you with 3. too

Whenever I right click and blueprint and select “Copy Reference” I always get a something that starts with “Blueprint.” However I seen other examples and tutorials where people were using “Copy Reference” and instead get something that starts with “Class.” My assumption is that it may be the difference between versions of the editor, but wanted to see if anyone knew exactly why the discrepancy exist. The examples I saw where people had “Class” were able to use UClass even though it was clearly a blueprint. Other examples that had a reference that started with “Blueprint” used UBlueprint. There is only one return result if I do a google for “ConstructorHelpers::FObjectFinder” and that is a post on the forums roughly a 2 months ago, so I’m worried if using UObject may be inefficient or possibly could just be a very new alteration to the engine.