UE4: A simple application of the SCENE COMPONENT blueprint

Scene Component is a less commonly used category in the blueprint class (especially for beginners), mainly because what it implements can be done in the same way as Actor classes, making it a bit redundant.

After using this class, I found that its function is more like an interface, which can be called by other blueprint classes (C++ classes can of course), and the operation method is simple, and the effect is obvious after implementation. Here I introduce a simple application for readers to understand and use this blueprint class.

The preparatory work

Start by creating a Scene Component blueprint class called HoverComponent.

Next, before writing the blueprint logic: Create two Float variables, named TraceLength and HoverForce,

  • TraceLength is used to adjust how much objects float,
  • HoverForce indicates the pressure exerted on the object as it floats.

TraceLength is set to an initial value of 150, which can be set as a public variable for real-time changes in the game; The initial value of HoverForce is 500000.

Event scheduling

The above nodes implement the Component initialization and simulated physics Settings.

Then call the Event Tick Event to perform ray detection in each frame of the game. The detection direction is the z-axis direction of the object and the amplitude is the previously set TraceLength

After the detection result is exposed, the normal phase collision vector and position vector are entered into a simple operation to obtain the object floating dynamic vector, which is added to Component

Finally, set the Component’s linear and angular shock absorbers, and you have a simple floating object blueprint.

The actual test

Create a Cube or Sphere static object component in the level, select it, add the HoverComponent made above in the Detail panel, change the Movable attribute of the object to Movable, place the static object component in the scene, run the level and test it. You can change the value of TraceLength in Default to see the effect

The author’s test results are shown in the figure below