UDN
Search public documentation:
ActorComponents
日本語訳
中国翻译
한국어
Interested in the Unreal Engine?
Visit the Unreal Technology site.
Looking for jobs and company info?
Check out the Epic games site.
Questions about support via UDN?
Contact the UDN Staff
中国翻译
한국어
Interested in the Unreal Engine?
Visit the Unreal Technology site.
Looking for jobs and company info?
Check out the Epic games site.
Questions about support via UDN?
Contact the UDN Staff
Actor Components
- Actor Components
- Overview
- Using Actor Components
- ActorComponent versus PrimitiveComponent
- Adding a Component
- Modifying a Component
- Removing a Component
- Component templates
- Creating component templates
- Instancing and attaching component templates
- Changing properties of a component template inherited from a super class
- Dynamically created components
- Common PrimitiveComponent options
- Actor collision and PrimitiveComponents
- Built-in component types
- Creating new component types
- Additional Notes
Overview
Using Actor Components
ActorComponent versus PrimitiveComponent
An ActorComponent is an object which can be attached to an actor in the world. A PrimitiveComponent is an ActorComponent which can be rendered and collided against.Adding a Component
Any Actor that’s instanced has a SpriteComponent that’s instanced along with it (unless a subclass removes Sprite from its Components array). Components referenced by the components array are bound to the Actor’s location. Example:class Actor extends Object; var const array<ActorComponent> Components; defaultproperties { Begin Object Class=SpriteComponent Name=Sprite Sprite=S_Actor HiddenGame=True End Object Components.Add(Sprite) }
Modifying a Component
Example:class Trigger extends Actor; defaultproperties { Begin Object Name=Sprite Sprite=S_Trigger End Object }
Removing a Component
Example:class StaticMeshActor extends Actor; defaultproperties { Components.Remove(Sprite) … }Since the Sprite component prototype is no longer referenced in the default properties of the StaticMeshActor class, it is not instanced with StaticMeshActors.
Component templates
Component templates are used to declare the default components of an actor class. A component template is a named object which contains the default properties for a component referenced in the default properties of a class. When the class is instanced, any component templates it references are instanced along with it. Component templates are inherited by subclasses of the class in which they are declared. Each subclass can override individual properties of the inherited template. An instance of a component template is serialized relative to the template's default properties. This allows instances of actor components to continue to receive changes to the template properties after being placed in a level.Creating component templates
Component templates are declared in the default properties of a class:Begin Object Class=SpriteComponent Name=Sprite Sprite=Texture2D'EngineResources.S_Actor' HiddenGame=True AlwaysLoadOnClient=False AlwaysLoadOnServer=False End Object
Instancing and attaching component templates
A component template will not be instanced with the class unless it is referenced by the class's default properties, and an actor component will not be attached to an actor unless it is in the actor's Components array. You can instance an actor component template with an actor class and automatically attach the instanced component to the actor instance by adding the component template to the actor's Components array in the default properties:Begin Object Class=SpriteComponent Name=Sprite // Sprite component properties are assigned values here End Object Components.Add(Sprite)
Changing properties of a component template inherited from a super class
Component templates are inherited by subclasses of the class the template is initially declared in. The subclass can override individual properties on inherited templates. This example inherits the Sprite template from Actor and modifies only the sprite texture property:Begin Object Name=Sprite Sprite=Texture2D'EngineResources.S_SkyLight' End Object
Dynamically created components
To dynamically create an instance of a component, use the UnrealScript new operator and call the actor's AttachComponent method to attach the new component to the actor. The parameter to the new operator is the outer object to create the component in; this should be the actor which it will be attached to. This ensures that the component's Outer reference doesn't unnecessarily prevent another actor from being garbage collected before the actor the component is attached to.local StaticMeshComponent NewComponent; NewComponent = new(self) class'StaticMeshComponent'; // Set the static mesh component's properties here. AttachComponent(NewComponent);To detach and free the component which you attached earlier, use the actor's DetachComponent method. Once no references to the component exist, it will be garbage collected.
Common PrimitiveComponent options
Type | Name | Description |
boolean | AlwaysLoadOnClient | If AlwaysLoadOnClient=False, and the primitive has HiddenGame=True and CollideActors=False, the primitive will not be loaded on game clients. |
boolean | AlwaysLoadOnServer | If AlwaysLoadOnServer=False, and the primitive has CollideActors=False, the primitive will not be loaded on game servers. |
boolean | BlockActors | If the PrimitiveComponent has collision enabled, BlockActors determines whether the primitive's collision will block other actors. |
boolean | CastShadow | True if the PrimitiveComponent should cast a shadow, false if it should not. |
boolean | CollideActors | If either of the actor's bCollideActors or the PrimitiveComponent's CollideActors properties are false, the primitive will have no collision. |
boolean | HiddenEditor | False if the PrimitiveComponent should be rendered in the editor, true if it should not. |
boolean | HiddenGame | False if the PrimitiveComponent should be rendered in the game, true if it should not. |
Actor collision and PrimitiveComponents
Collision tests will be performed against all of the colliding PrimitiveComponents attached to an actor, but when an actor moves, it only performs a test for a single PrimitiveComponent. This PrimitiveComponent is chosen by setting the Actor property CollisionComponent to reference the component to be used for actor movement collision checks. When the actor moves, it will take the bounding box of the component referenced by CollisionComponent and sweep it against all colliding PrimitiveComponents.Built-in component types
- PrimitiveComponent
- ArrowComponent
- CameraConeComponent
- CylinderComponent
- DrawFrustumComponent
- MeshComponent
- StaticMeshComponent
- SkeletalMeshComponent
- ParticleSystemComponent
- SpriteComponent
- LightComponent
- DirectionalLightComponent
- PointLightComponent
- SpotLightComponent
- SkyLightComponent
- AudioComponent
- HeightFogComponent
- SceneCaptureComponent
- SceneCapture2DComponent
- SceneCaptureCubeMapComponent
- SceneCaptureParaboloidComponent
- SceneCaptureReflectComponent