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.
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? (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:
Within the WorldOutliner in the Details of your CineCameraActor you can select your Actor as “Target to Track”:
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.
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.
(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.
Just to give you you a picture of one of my [projects][1] how this plug&config&play modularity can look like:
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 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
(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)
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
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.
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
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.
Select your cam you want to follow (within the sequencer or within the level) so you will see the small preview window.
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 Thx
Just don’t get lost in watching amazing things over and over and over again with the sequencer