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"

Need help creating a DefaultSubObject of a widget Component Blueprint

Hi, I'm making an RPG, and I am trying to create a widget component in c++ based off of a WidgetComponent Blueprint, but I keep creating Nullptrs and crashing my editor.Here is what my code currently looks like in my PowerEntity.cpp (parent c++ class of all my entities):

 //Calling and trying to cast the blueprint as UNameplateController:
 static ConstructorHelpers::FObjectFinder<UNameplateController> NameplateReference(TEXT("Blueprint'/Game/Power/UI/NamePlates/BP_NameplateController.BP_NameplateController'"));
     if (NameplateReference.Succeeded()) {
         this->NameplateController = NameplateReference.Object;
 }

First problem is that the editor is not finding the blueprint at the specified path that I copied directly from, and I get this error:

 LogUObjectBase: Warning: Error: CDO Constructor (PowerEntity): Failed to find Blueprint/Game/Power/UI/NamePlates/BP_NameplateController.BP_NameplateController

I also tried setting the FObjectFinder class to UClass, and casting NameplateReference as UNameplateController, and while NameplateReference had a value, NameplateController was null after setting it equal to the casted NameplateReference.Object.

I've been trying to fix this for days, and I've looked at so many threads, and nothing seems to be working. I would really really appreciate it if someone took some time to help me resolve this.

Product Version: UE 4.20
Tags:
more ▼

asked Nov 13 '18 at 04:34 AM in C++ Programming

avatar image

The_Chodesen_One
3 1 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hello,

Is NameplateController a WidgetComponent pointer?

If so, you should use the CreateDefaultSubobject() function to create a new actor component.

You should also use FClassFinder to get the TSubclassOf for your blueprintclass. Then use the .Get() function to get the UClass which you can pass into your CreateDefaultSubobject function.

 static ConstructorHelpers::FClassFinder<UNameplateController> NameplateReference(TEXT("Blueprint'/Game/Power/UI/NamePlates/BP_NameplateController.BP_NameplateController'"));
 
 NameplateController = static_cast<UNameplateController*>(CreateDefaultSubobject(TEXT("NameplateController"), UNameplateController::StaticClass(), NameplateReference.Class.Get(), true, false, false));
 NameplateController->SetupAttachment(RootComponent);




~ Dennis / MazyModz

more ▼

answered Nov 14 '18 at 06:20 PM

avatar image

MazyModz
266 4 5 6

avatar image The_Chodesen_One Nov 14 '18 at 09:20 PM

First off, thank you so much for taking the time to help me, I really appreciate it.

NameplateController is a pointer to my UNameplateController class which inherits from UWidgetComponent.

Using your code, I still get this error:

alt text

The second part of your code should work though assuming that I am able to get the class from the first part, which is currently not working. Any ideas?

avatar image The_Chodesen_One Nov 14 '18 at 09:24 PM

Nevermind, I got it to work by changing the path to "/Game/Power/UI/NamePlates/BP_NameplateController", and the WidgetComponent is successfully attaching to my entites in the editor, Thanks so much for the help!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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