Detect Property Change in ActorComponent?

Hello All,

I have trying to understand ActorComponents, and I have created a very simple component for learning. This component should rotate it’s owner on Z-Axis by the value specified in publicly exposed variable. Problem is that I can’t figure out how to execute the blueprint graph which does rotation. It shouldn’t happen on “Event Begin Play” or “Event Tick”. It should only happen when variable value is changed either in editor or during gameplay. And it should be animatable through level sequence.

The actual purpose was to allow an actor to “ride” along a spline based on position value (0 to 1). if value is 0 then actor sits at start of spline, if value is 1 actor sits at end of spline. This is very similar to camera rig rail.

I already have a camera rig rail setup working. But I want “LookAt” target of camera to ride along a spline ahead of camera itself.

Many thanks

Is there a better way to do this?

1 Like

Hi there,

What I understand:

  • You have a camera on one spline path (or rig. does not matter in this case).
  • And an Actor on another spline path.
  • You want the Camera to always look at the Actor while both are moving along their splines.

So let’s skip to the “better way”, shall we? :slight_smile: (Assuming i understood what you want)

Is there any reason you want the Actor to move with 0…1 values? You would be better off with moving the actor within the Sequencer like you do with the camera.
If you need the ActorComponent to rotate your Cam then you can use the CineCameraActor instead, where you can define your “Actor to Track”.

Here the setup for what i think you actually want to do:

So you put both CineCameraActor and your Actor into the level and drag both into the sequencer. You can define the movement track of both in the same way:

99913-sequencer.jpg

Within the WorldOutliner in the Details of your CineCameraActor you can select your Actor as “Target to Track”:

99914-worldoutlinercam.jpg

If this is what you want, than you should be good to go with this approach. But if you want the Actor to look at the camera (or something completely different), I can provide you this solution as well if you need. You actually do not need the ActorComponent as well if it is just for this usecase.

I hope that helps, feel free to ask :slight_smile: Marooney

Thanks. I will do this as explained by you.
However, I still want to know about ActorComponent blueprints. Can my ActorComponent blueprint affect its owner’s construction script?

How do I execute the graph of an ActorComponent if a variable changes? There is no construction script for an ActorComponent BP. I am only asking because I think this will be useful for creating attachable behavior for actors. I know Actor BP already does this, but this way seems more self-contained and cleaner.

Thanks.

(not able to post this as comment, so here we go:)

“self-contained and cleaner” makes me really happy when someone supports this effort of modularity and reusability and flexibility. :slight_smile:

Just to give you you a picture of one of my [projects][1] how this plug&config&play modularity can look like:

100140-actorcomponents_modularity.jpg

You cannot change any construction of an object by a different object. You can only access it when already constructed. So the Actor will call the Component by the Variable that is created for the Component. And the Component can access the Actor with GetOwner. When you access the owner you want to avoid specific casts to keep reusability. If you create a Component for Pawns only then of course you can cast to Pawn and keep flexibility within every Pawn-Inherited Blueprint.

I have actually built these samples before I realized what you are going for, so I am happy to use them now, since i know that I understand your question so far:

If you need to react to value changes you need to check for them every tick in many cases. Still avoids the whole Tick execution. That is what I do for the SequencerDemo in my demo-project. Sequencer sets values only when they change.

This sample is basically the “Actor to Track” approach like the CineCameraActor does. A self contained version of the previous sample.

This sample is for situations where you are able to access functions and when you are not restricted to variables (like with the Sequencer). You just get rid of the Tick Event and you can even disable Ticks at all for this ActorBlueprint.

And this sample is for situations with replication, so you can use the benefit of the OnRep function. It is basically a mixture of RotationComponent_ByVariable and RotationComponent_ByFunction. Where the function gets called on value change. But if the value is set every tick, only the clients will call OnRepon change, the server calls OnRep every tick no matter if value has been changed or not, so you still need to do the change check yourself :confused:
(I think I have experienced an issue with this approach: OnRep does not get called if Variable gets changed by the Sequencer. Not sure anymore)

I hope that helps :slight_smile:

Keep in mind there are still some issues with overriding values of inherited components in an actor (If you change properties of the blue components like in the picture above). They need to be editable and even then they can make your life hard sometimes if they are ignored and need to be reset or so. Strange things are happening, but just in rare cases :slight_smile:

And if you inherit from an Blueprint, you can of course change the constructor and EventBeginPlay and every other function/event you would like to. Either you override it completely and do not call the parent node (orange node). You can put your own initialization after the parent node, or even before as you wish for execution order.

I don’t know any blueprint solution but in c++ PostEditChangeProperty will be called when a variable value is changed!

Oh that’s exactly what I was looking for. It’s so elegant and simple. You are amazing.
Before this, I was doing modularity with Actor BP’s. That approach caused me to have large number of blueprint objects in scene and world outliner

Thanks a lot.

One last question: This will not work in editor, right? We can only see it in action during gameplay. A LookAt Component BP which works in editor as well as gameplay would be great, but I think it’s not possible. We do not have access to editor ticks.

Well you will be happy about that:

  1. Open the sequencer
  2. Select your cam you want to follow (within the sequencer or within the level) so you will see the small preview window.
  3. Now you can use the Sequencer play buttons within the LevelViewport or within the Sequencer. Or you can drag the time bar with your mouse to scrub through the timeline and you will see the current view of the camera within the preview.

You can also run everything as Simulation if you have actors in there that are moving on its own and therefore are not controlled by the sequencer. (Like I needed to do in my project). So still in editor, with the desired Cam and its preview window.

Here the fancy part: In the toolbar: Window → ViewPorts → Check a new Viewport.
In the Viewport: Click the Perspective Button and select your desired cam.

So you have pretty much everything in editor with full time positioning control within the Sequencer.

Hope that helps. Since your question is about ActorComponents and your Title is pretty well formulated for search-engine-friendliness: Please leave an UpVote for the this answer if you think this helps your situation. So that this answer does not look like a stupid wasted misplaced answer to your precise ActorComponent question :slight_smile: Thx :slight_smile:

Just don’t get lost in watching amazing things over and over and over again with the sequencer :slight_smile:

Thanks a lot. :slight_smile: