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"

UActorComponent: When to Register vs. Activate, and how?

I haven't been able to find any details online whether to use RegisterComponent or Activate, nor what the difference is; so, the first part the of the question is when to use RegisterComponent() or Activate()?

I would normally test this out and see what happens when either is called, but the kicker is I can't get either to work. In my header, I have the whole UCustomComponent* MyComponent deal, but putting either MyComponent->RegisterComponent() or MyComponent->ActivateComponent() in my actor's BeginPlay crashes the editor on play; I tried putting them instead in the actor's constructor, but that corrupted the project and I had to rebuild Intermediate and Binaries.

What do I do?

Product Version: UE 4.10
more ▼

asked Feb 05 '16 at 01:54 AM in C++ Programming

avatar image

165 20 29 39

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

1 answer: sort voted first

Hi Kowbell!

But you created first component itself, before call any functions for it? That's description for RegisterComponent method:

 /** Register this component, creating any rendering/physics state. Will also adds to outer Actor's Components array, if not already present. */
 void RegisterComponent();

And that's description for Activate method:

  * Activates the SceneComponent
  * @param bReset - The value to assign to HiddenGame.
 UFUNCTION(BlueprintCallable, Category="Components|Activation")
 virtual void Activate(bool bReset=false);

So Activate just starts(or restarts) component's tick timer and enables Tick function if it was disabled. RegisterComponent register it inside it's owner and inside owner's world.

But before call above methods you must create component itself. If you want to create it within constructor then you can call CreateDefaultSubobject(...) method. If you want to create it dynamically then you can call NewObject method (but I didn't test it this way, so check these 2 links if you want: first, second)


more ▼

answered Feb 05 '16 at 04:37 AM

avatar image

236 12 5 16

avatar image Kowbell Feb 06 '16 at 02:38 PM

Ah! Forgot the CreateDefaultSubobject. Thanks!

(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