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"

Function after component is initialized

Hi,

is there a way to call a function that is executed in the editor after the ActorComponent's variables are initialized from the properties we set in the editor? With actors construction script / constructor works fine, but the component's variables aren't set when the component's constructor or when the owner's constructor is executed.

Thanks,

Elathan

Product Version: UE 4.10
Tags:
more ▼

asked Jan 12 '16 at 02:07 PM in Using UE4

avatar image

Elathan
426 25 29 59

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

2 answers: sort voted first

Hi,

Try with PostInitializeComponents

 //.h
 virtual void PostInitializeComponents() override;
 
 //.cpp
 void AYourActorClass::PostInitializeComponents()
 {
     Super::PostInitializeComponents();
 
     //... your code
 }

Best regards

more ▼

answered Jan 12 '16 at 02:26 PM

avatar image

nan2cc
507 23 14 38

avatar image Elathan Jan 12 '16 at 02:31 PM

Thanks.

Unfortunately it's an ActorComponent, not an actor. I also tried PostInitProperties() - it is called every time I change a value in the editor on the component, but the result is the same: I see default values.

avatar image nan2cc Jan 12 '16 at 02:37 PM

Ohh on ActorComponent, sorry . . . well try with InitializeComponent.

Initializes the component. Occurs at level startup. This is before BeginPlay (Actor or Component). All Components in the level will be Initialized on load before any Actor/Component gets BeginPlay Requires component to be registered, and bWantsInitializeComponent to be true.

 //.h
 virtual void InitializeComponent() override;
  
 //cpp
  void UYourComponentClass:: InitializeComponent()
  {
     Super::InitializeComponent();
     //Your code
  }

Best regards

avatar image Elathan Jan 12 '16 at 02:43 PM

That wouldn't help, because I need something which is executed in the editor, not just before the game starts.

avatar image nan2cc Jan 12 '16 at 03:27 PM

OK, I understand, try with: PostEditChangeProperty this function is called ONLY ON EDITOR when a property on this object has been modified externally.

It is from UObject, so probably you can use in a ActorCOmponent but, personally, I only have used in Actor class. But try, maybe it work for you.

IMPORTANT: Note the #if WITH_EDITOR macro, because this function is just for the Editor

 //.h
 #if WITH_EDITOR
 virtual void PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent) override;
 #endif // WITH_EDITOR
 
 //.cpp
 void YourClass::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent)
 {
     Super::PostEditChangeProperty(PropertyChangedEvent);
 
     //... your code
 }

Try it and let me know if this work for you.

Best regards

avatar image Elathan Jan 12 '16 at 03:42 PM

Thanks, it actually worked :)

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

Have you tried overriding OnComponentCreated() ?

more ▼

answered Jan 12 '16 at 02:09 PM

avatar image

TTaM
1.7k 81 28 81

avatar image Elathan Jan 12 '16 at 02:22 PM

Thanks for your reply.

I just tried it - doesn't work. Float and int values are 0, pointers are NULL, no matter what value I set in the editor.

Maybe the are initialized only when the game begin?

(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