x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Product Version: Not Selected
Tags:
more ▼

asked Sep 29 '14 at 06:11 AM in Using UE4

avatar image

MTree
41 2 5 60

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

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;
 }

more ▼

answered Sep 29 '14 at 06:34 AM

avatar image

TimGS
611 19 23 235

avatar image MTree Sep 30 '14 at 03:00 AM

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.

(comments are locked)
10|2000 characters needed characters left

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.

more ▼

answered Sep 29 '14 at 04:17 PM

avatar image

MTree
41 2 5 60

avatar image TimGS Sep 29 '14 at 05:55 PM

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

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question