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"

Why is my object's constructor called so many times?

I have an actor that has a custom USceneComponent I made attached to it. placing a breakpoint in the constructor, I am seeing that the constructor is called many times.

I have read that UE4 does construction in a obscure way that causes it to construct multiple times, however, I am seeing a LOT of construction, and at times I wouldn't expect it to occur.

Launch of the editor, constructor 5, destructor 1

Launching BP editor for my actor, constructor 1, destructor 0

Switching to the viewport, constructor 1, destructor 0

Closing the BP editor for my actor, constructor 0, destructor 0

Moving my actor in the level: constructor 1, destructor 0

Moving my scene component in the editor : constructor 1, destructor 0 (per frame?)

Additionally, I have a UProperty UStaticMeshComponent* that appears to be always null, each time the constructor is reached. The property has been set in the actor.

Is this normal behavior? Why? Why is the constructor called so many more times than the destructor?

Product Version: UE 4.19
more ▼

asked May 30 '18 at 05:13 AM in C++ Programming

avatar image

58 13 12 19

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

1 answer: sort voted first

Because constructors are useful in the editor, not only in-game, Unreal Engine tries to make sure your object is always updated according to its constructor.

Lets imagine an actor that has a vector with 3d widget, and a wall is stretched from the origin of your actor to that 3d widget. Now, lets assume you move this actor around in your world. Because construction is dependent on the location, unreal has to re-construct the object when you move.

So as far as i know, yes, it is normal behaviour. (But im not sure). It has been like this since at least 4.10.

more ▼

answered May 30 '18 at 11:21 AM

avatar image

397 5 5 13

avatar image Zamithal May 31 '18 at 01:00 AM

Wouldn't the lack of destructor calls indicate a memory leak? What is it doing with all these extra references to objects it is holding on to?

avatar image FlameOfIgnis May 31 '18 at 01:07 AM

Well, again, i always thought unreal handled constructors a bit differently, like recalling them when an actor is updated instead of destructing/reconstructing them, but i never thought about the memory aspect of the subject, and to be honest, i have no clear answer to give here since my knowledge on how unreal is handling this is limited

However, i found this post that explains whats going on a lot better than i ever could, and i hope it can answer some of the questions you have:


(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