Change Component Properties at Runtime
Last updated
Last updated
You can easily change component properties at runtime as most of these properties are writable in blueprint. You can access properties by using the Get and Set nodes from the component you want to modify.
Here is an example. When the character overlaps with a trigger box at the specified place, the camera distance will smoothly increases to 600.
The blueprint is quite simple. First call the GetActiveCamera node and check its validity. Then get its follow component and cast it to ScreenFollow. Last use a Timeline node to interpolate from the default camera distance to the target camera distance.
You can define various custom functions and place them in a library. It will be very convenient next time you use these functions.
V0.2.1 added a new blueprint node SetPropertyByName, which allows you to set any numeric/struct type property of any object in an async manner. It supports nested properties, that is, you can use PropertyName_A.PropertyName_B.PropertyName_C to access and set proerties. Reference the node list for a more comprehensive introduction to the node itself.
In the following example, let us use this node to modify ScreenFollow
component's CameraDistance
property.
Create a new camera class with the ScreenFollow
component. It's named ThirdPersonCamera
here.
Call this camera in blueprint and use the SetPropertyByName
node to set the CameraDistance
property in the ScreenFollow
component. Here the destination value is 1000 and blend duration is 5 seconds.
Run the game and you will see the camera distance changes as expected.
As property names can be nested, you can achieve this same purpose using one of the following three ways.