I have seen threads discussing the C++ “equivalent” (at least a close equivalent) of a Blueprint (Actor’s) Construction Script (eg. equivalent of construction script in c++ - C++ Gameplay Programming - Unreal Engine Forums ). These suggested the class’ constructor (it only gets executed once, not when I change something on the actor in the editor) and OnConstructed() as the “replacement”, which seems to be the closest I got to something that runs whenever my actor changes in the editor, but it seems I’ve found a case where they aren’t working alike.
So here’s what I want to do: I want to run a function each time my (root) SplineComponent changes (even in the editor). If I make a Blueprint Actor, the Construction Script will run whenever I do something with the SplineComponent (it triggers multiple times while I’m moving a control point, it runs when I create a new control point or when I remove a control point). The closest I can get to it in C++ is by implementing OnConstruction(), which sadly doesn’t work in all the mentioned cases:
- It only runs once when moving a control point: at the end (this is not a huge problem for me)
- It **does not run at all when I delete a control point (this is a huge problem for me as I can’t keep track of deleted points)
Since I found no way to listen for my SplineComponent’s changes, I ended up with this solution (trying to implement something that runs like the Construction Script), but as you can see, it still doesn’t work as intended. I’d like to avoid ticking, so I ignored that, and I would also like to do this in C++. I tried these as well:
- **PostEditChangeChainProperty **or **PostEditChangeProperty **are not called when I make changes to the spline in the editor view (they do when I change something on the Details panel, but I can’t really edit my spline from there)
- I found no extensible (virtual) method on **SplineComponent **that would allow me to fire a delegate that I can listen to in my Actor: *UpdateSpline *is not virtual (I’d try to fire a delegate from there) and **PostEditChangeProperty **and its sibling are again not fired when the spline is edited from the editor view.
- I’ve looked through AActor’s lifecycle calls (reference: https://docs.unrealengine.com/en-US/…tor/index.html ) but I found no other point worthy of investigating (I tried PreRegisterAllComponents, PostActorCreated and PreInitializeComponents none seem to work )
I’d like to ask if any of you know of something that I could utilize (without changing the engine’s source code or getting my actor(s) to tick) to listen for a SplineComponent’s changes? The spline likely won’t change in runtime, but I would like to run a function whenever it does, at least in the editor. Is there something trivial that I’m missing?
I attached a small component of a spline actor that demonstrates my issue (when I delete a control point, the OnConstructed() method doesn’t get called, which in this case would print a log message, in all the other cases it prints the string “Hello!”).