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"

Create and attach a component from a UClass

Hi there guys, i'm trying to make a power up system, in wich the character can attach a component of certain type.

 UFUNCTION(BlueprintCallable, Category = "Vertex Character", meta=(Tooltip="Absorb the given essence into the character"))
     virtual void AbsorbEssence(TSubclassOf<class UEssenceComponent> EssenceClass);

This is made so any blueprint powerup can call the AbsorbEssence with the type of the EssenceComponent that i want

The problem is that i given this TSubclassOf Object (UClass) i can't attach the component or create it.

I tried doing:

 essenceComponent = EssenceClass->GetDefaultObject<UEssenceComponent>();

But the engine crashes because something something about the world of the actor not existing. (its a ensure that RegisterComponent does that my component fails).

I'm banging my head here, any idea how can i dinamycally add these components to my actor given the UClass?

Product Version: UE 4.13
more ▼

asked Oct 21 '16 at 09:05 PM in C++ Programming

avatar image

277 11 20 33

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

1 answer: sort voted first

Check this answer


Maybe there is a problem on how you are constructing the essenceComponent object

more ▼

answered Oct 21 '16 at 09:14 PM

avatar image

600 17 9 32

avatar image HeavyBullets Oct 22 '16 at 07:52 PM

Just one question, ConstructObject is deprecated, but it's the function that allows me to specify a UClass parameter apart from theTemplate return of the function, does NewObject have something like that?

avatar image MacDx Oct 22 '16 at 08:32 PM

Yup the NewObject function's second parameter is exactly that

(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