Unreal Engine 4 学习笔记(七):Component

Component用于构建Actor的行为,不同的Component具有不同的功能,常用的Component及它们的类继承的关系如下:

UObject
    UActorComponent
        UMovementComponent
		UProjectileMovementComponent
		UNavMovementComponent
			UPawnMovementComponent
				UCharacterMovementComponent
	USceneComponent
		UWidgetInteractionComponent
		ULightComponentBase
			ULightComponent
				UPointLightComponent
		USpringArmComponent
		UCameraComponent
		UPrimitiveComponent
			UBrushComponent
			UParticleSystemComponent
			UShapeComponent
				UCapsuleComponent
				USphereComponent
				UBoxComponent
			UMeshComponent
				UStaticMeshComponent
				UWidgetComponent

UActorComponent

ActorComponents have the ability to be updated each frame via their TickComponent() function. This allows Components to perform type-specific, per-frame calculations.
In order for a Component to be updated, it must be registered, set to tick (bComponentNeverTicks=false), and have its tick function setup.

UMovementComponent

MovementComponent is an abstract component class that defines functionality for moving a PrimitiveComponent (our UpdatedComponent) each tick.
Base functionality includes:
   - Restricting movement to a plane or axis.
   - Utility functions for special handling of collision results (SlideAlongSurface(), ComputeSlideVector(), TwoWallAdjust()).
   - Utility functions for moving when there may be initial penetration (SafeMoveUpdatedComponent(), ResolvePenetration()).
   - Automatically registering the component tick and finding a component to move on the owning Actor.
Normally the root component of the owning actor is moved, however another component may be selected (see SetUpdatedComponent()).
During swept (non-teleporting) movement only collision of UpdatedComponent is considered, attached components will teleport to the end location ignoring collision.

UProjectileMovementComponent

A ProjectileMovementComponent updates the position of another Component during its tick. Behavior such as bouncing after impacts and homing toward a target are supported by this type of Component.
Normally the root Component of the owing Actor is moved, however another Component may be selected (see SetUpdatedComponent).
If the Updated Component is simulating physics, only the initial launch parameters (when initial velocity is non-zero) will affect the projectile, and the physics simulation will take over from there.

UPawnMovementComponent

PawnMovementComponent can be used to update movement for an associated Pawn.
It also provides ways to accumulate and read directional input in a generic way (with AddInputVector(), ConsumeInputVector(), etc).

UCharacterMovementComponent

The CharacterMovementComponent allows avatars not using rigid body physics to move by walking, running, jumping, flying, falling, and swimming. It is specific to Characters and cannot be implemented by any other class.
It is automatically added when creating Blueprints based on the Character class and not manually added.
Properties that can be set include values for falling and walking friction, speeds for travel through air and water and across land, buoyancy, gravity scale, and the physics forces the Character can exert on Physics objects.
The CharacterMovementComponent also includes root motion parameters that come from the animation and are already transformed in world space, ready for use by physics. See Root Motion for more information.

USceneComponent

Scene Components are a subclass of Actor Components that have a transform, that is, a relative location, rotation, and scale.
Just like Actor Components, Scene Components aren't rendered themselves, but can use their transform for various things, such as spawning other objects at a fxed offset from an Actor

SceneComponents are an extension of ActorComponents that have a transform, i.e. location, rotation, and scale.
Each SceneComponent has its own FTransform, generally for internal use, that describes its world-relative location, rotation, and scale.
They also have an additional RelativeLocation vector, RelativeRotation rotator, and RelativeScale3D vector used which can act as either relative to their parent Component or relative to the world.
By default, RelativeLocation, RelativeRotation, and RelativeScale3D are relative to their AttachParent.
These values can be forced to be relative to the world using the bAbsoluteLocation, bAbsoluteRotation, and bAbsoluteScale properties.
Setting any of these to true will cause the corresponding property to be world-relative.
Even when using parent-relative transform values, it is still possible to set translation and rotation using absolute world values via the methods shown below:
SceneComponent::SetWorldLocation()
SceneComponent::SetWorldRotation()

UPrimitiveComponent

Primitive components are the most complex type of Actor Component because they not only have a transform, but are also rendered on screen.

PrimitiveComponents are SceneComponents that contain or generate some sort of geometry, generally to be rendered or used as collision data.
There are several subclasses for the various types of geometry, but the most common by far are the CapsuleComponent, StaticMeshComponent, and SkeletalMeshComponent.
CapsuleComponents generate geometry that is used for collision detection, but not rendered;
while StaticMeshComponents and SkeletalMeshComponents contain pre-built geometry that is rendered, but can also be used for collision detection.

UCameraComponent

Represents a camera viewpoint and settings, such as projection type, field of view, and post-process overrides.
The default behavior for an actor used as the camera view target is to look for an attached camera component and use its location, rotation, and settings.

USpringArmComponent

This component tries to maintain its children at a fixed distance from the parent,
but will retract the children if there is a collision, and spring back when there is no collision.

UShapeComponent

ShapeComponent is a PrimitiveComponent that is represented by a simple geometrical shape (sphere, capsule, box, etc).

UCapsuleComponent

A capsule generally used for simple collision. Bounds are rendered as lines in the editor.

UMeshComponent

MeshComponent is an abstract base for any component that is an instance of a renderable collection of triangles.

UStaticMeshComponent

StaticMeshComponent is used to create an instance of a UStaticMesh. A static mesh is a piece of geometry that consists of a static set of polygons.            

UWidgetComponent

The widget component provides a surface in the 3D environment on which to render widgets normally rendered to the screen. Widgets are first rendered to a render target, then that render target is displayed in the world.

UWidgetInteractionComponent

This is a component to allow interaction with the Widget Component. This class allows you to simulate a sort of laser pointer device, when it hovers over widgets it will send the basic signals to show as if the mouse were moving on top of it.
You'll then tell the component to simulate key presses, like Left Mouse, down and up, to simulate a mouse click.

UMovementComponent含有如下属性:

USceneComponent* UpdatedComponent;

UpdatedComponent一般生于Actor的RootComponent,用于控制Actor的运行行为。

USceneComponent含有如下属性:

USceneComponent* AttachParent;
TArray<USceneComponent*> AttachChildren;

分别用于存放父USceneComponent,和其包含的子USceneComponent。

Actor的RootComponent就是一个USceneComponent。USceneComponent中还有以下三个方法需要注意一下:

/**
 * Attach this component to another scene component, optionally at a named socket. It is valid to call this on components whether or not they have been Registered.
 * @param  InParent				Parent to attach to.
 * @param  InSocketName			Optional socket to attach to on the parent.
 * @param  AttachType			How to handle transform when attaching (Keep relative offset, keep world position, etc).
 * @param  bWeldSimulatedBodies Whether to weld together simulated physics bodies.
 * @return True if attachment is successful (or already attached to requested parent/socket), false if attachment is rejected and there is no change in AttachParent.
 */
DEPRECATED(4.12, "This function is deprecated, please use AttachToComponent instead.")
bool USceneComponent::AttachTo(USceneComponent* InParent, FName InSocketName = NAME_None, EAttachLocation::Type AttachType = EAttachLocation::KeepRelativeOffset, bool bWeldSimulatedBodies = false);
/**
* Attach this component to another scene component, optionally at a named socket. It is valid to call this on components whether or not they have been Registered, however from
* constructor or when not registered it is preferable to use SetupAttachment.
* @param  Parent				Parent to attach to.
* @param  AttachmentRules		How to handle transforms & welding when attaching.
* @param  SocketName			Optional socket to attach to on the parent.
* @return True if attachment is successful (or already attached to requested parent/socket), false if attachment is rejected and there is no change in AttachParent.
*/
bool USceneComponent::AttachToComponent(USceneComponent* InParent, const FAttachmentTransformRules& AttachmentRules, FName InSocketName = NAME_None );
/** 
* Initializes desired Attach Parent and SocketName to be attached to when the component is registered.
* Generally intended to be called from its Owning Actor's constructor and should be preferred over AttachToComponent when
* a component is not registered.
* @param  InParent				Parent to attach to.
* @param  InSocketName			Optional socket to attach to on the parent.
*/
void USceneComponent::SetupAttachment(USceneComponent* InParent, FName InSocketName = NAME_None);

猜你喜欢

转载自blog.csdn.net/netyeaxi/article/details/81385863