Constructor of components are called on any state change?

I had a really long and detailed debug of some strangeness, but I found that the MoverComponent::MoverComponent appears to be called from the blueprint if any state changes. I found this out because when I converted the mesh I was testing on to a blueprint ( similar to what Sam did ), the Mover suddenly stopped working.

This sort of negates the possibility of having a component state in code … what’s the best way to handle this?

That definitely shouldn’t be the case unless the MoverComponent is being repeatedly recreated. A Constructor in C++ should only be triggered when the object is instantiated. If it is triggered a second time, it is because a new object is being created. Of course, creating a new instance of the original blueprint would also do this.

I hope this makes sense.

Thanks BeeGeeDee, up until now … I would have said exactly the same.

The only reasonable conclusion here is that Unreal is it seems … recreating the components. Or perhaps some sort of object pooling. Not sure.

The level is complicated, however there is 1BP that has 1 Mover component attached to it. There are no other MoverComponents attached to anything.

The sequence is:

  1. Build / Livecode
  2. BeginPlay
  3. Click “Should Move” on Mover ( in my mover I do the move, and then uncheck this )
  4. Click “Should Move” on Mover again ( this should return to start, but does not )

So my real problem is that my class state is reset ( which naturally if the constructor is being re-called ). What I find VERY interesting is that all the timestamps match even though sequentially in the log they appear at the above events.

I will amend my question then to this: How do I effectively store component state while attached to a blueprint?

# Logging in constructor ( UMoverComponent::UMoverComponent() )
UE_LOGFMT(LogTemp, Warning, "Constructor ({is})({who})", isForward, GetFName());

# After build
Mon Mar 25 21:53:28 EDT 2024  Warning      LogTemp                   Constructor (true)(Default__MoverComponent)

# After BeginPlay
Mon Mar 25 21:53:28 EDT 2024  Warning      LogTemp                   Constructor (true)(Mover)

# After I first "Should Move" toggle
Mon Mar 25 21:53:28 EDT 2024  Warning      LogTemp                   Constructor (true)(Mover)

# After second "Should Move"
Mon Mar 25 21:53:28 EDT 2024  Warning      LogTemp                   Constructor (true)(Mover)

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms