🏘️ InstancedStaticMesh
实例化静态网格体实体允许生成一个能够高效渲染多个实例的网格体。

Instanced Static Meshes are like StaticMeshes, but instead of being a single instance, it supports rendering a group of identical meshes, way more efficiently.
If you rely on adding and removing instances dynamically. It can be a good idea to hide the instance instead of removing it, as removing an instance will potentially cause all indexes to be reordered.
For that, just set the instance scale to zero as Vector(0, 0, 0):
local my_index = 123
my_instanced_static_mesh:SetInstanceTransform(my_index, nil, nil, Vector(0, 0, 0))
Any mesh that you want to use with an Instanced Static Mesh must have it's materials set to Used with Instanced Static Meshes in the Material Editor.
🛠 构造函数
Default Constructor
No description provided
local my_instancedstaticmesh = InstancedStaticMesh(location, rotation, static_mesh_asset, collision_type?, instances?, defer_spawn?)
Parameters
| Type | Name | Default | Description |
|---|---|---|---|
| Vector | location | Required parameter | No description provided |
| Rotator | rotation | Required parameter | No description provided |
| StaticMesh Reference | static_mesh_asset | Required parameter | No description provided |
| CollisionType | collision_type | CollisionType.Auto | No description provided |
| table | instances | {} | 包含初始实例的数组 with this format |
| boolean | defer_spawn | false | 传入 true 以避免立即将该实体发送给客户端,从而在你想要通过设置多个配置来调整它时提高性能。最后必须调用 FinishSpawn() |
🗿 静态函数
Inherited Entity Static Functions
Base Entityscripting-reference/classes/base-classes/entity
| Returns | Name | Description | |
|---|---|---|---|
| table of Base Entity | GetAll | 返回一个包含调用此方法的类中所有实体的表 | |
| Base Entity | GetByIndex | 返回该类中指定索引处的特定实体 | |
| integer | GetCount | 返回该类当前存在的实体数量 | |
| table of table | GetInheritedClasses | 获取使用 继承系统 创建的、直接继承自该类的所有子类列表 | |
| iterator | GetPairs | 返回一个包含该类所有实体的迭代器,用于 pairs() 循环 | |
| table or nil | GetParentClass | 如果该类是使用 继承系统 创建的,则获取其父类 | |
| table | Inherit | 使用 继承系统 继承此类 | |
| boolean | IsChildOf | 如果该类是使用 继承系统 创建的,检查此类是否为另一个类的子类 | |
| function | Subscribe | 为该类的所有实体订阅一个 事件 | |
| function | SubscribeRemote | 订阅从服务器调用的自定义远程事件 | |
Unsubscribe | 退订此包内该类中此 事件 的所有回调,或者仅取消传入的特定回调 |
This class doesn't have own static functions.
🦠 函数
Inherited Entity Functions
Base Entityscripting-reference/classes/base-classes/entity
| Returns | Name | Description | |
|---|---|---|---|
BroadcastRemoteEvent | 直接在此实体上向所有玩家调用自定义远程事件 | ||
BroadcastRemoteInRadiusEvent | 直接针对此实体调用自定义远程事件,并将该事件传递给半径范围内的所有玩家 | ||
CallRemoteEvent | 直接在此实体上向特定玩家调用自定义远程事件 | ||
CallRemoteEvent | 直接在此实体上调用自定义远程事件 | ||
CallRemotePlayersEvent | 直接在此实体上调用自定义远程事件,并将事件传递给玩家列表 | ||
Destroy | 销毁该实体 | ||
FinishSpawn | 完成生成过程,如果实体是通过 defer_spawn 生成的,则将实体发送给客户端 | ||
| table of string | GetAllValuesKeys | 获取所有值键的列表 | |
| table | GetClass | 获取该实体的类 | |
| integer | GetID | 获取该实体的全网通用网络 ID(在客户端和服务器上相同) | |
| any | GetValue | 获取此实体上存储在给定键处的 值 | |
| boolean | HasAuthority | Gets if the local context has authority over this Entity (true if spawned by the client, false if spawned by the server) | |
| boolean | IsA | 递归检查此实体是否继承自某个类 | |
| boolean | IsBeingDestroyed | 如果该实体正在被销毁,则返回 true | |
| boolean | IsValid | 如果该实体有效(即未被销毁且指向一个有效的实体),则返回 true | |
SetValue | 在此实体中设置一个值 | ||
| function | Subscribe | 在这个特定实体上订阅一个事件 | |
| function | SubscribeRemote | 在这个特定实体上订阅一个从服务器调用的自定义远程事件 | |
Unsubscribe | 退订此包内该实体中此 事件 的所有回调,或者仅取消传入的特定回调 |
Inherited Actor Functions
Base Actorscripting-reference/classes/base-classes/actor
| Returns | Name | Description | |
|---|---|---|---|
AddActorTag | 向该 Actor 添加一个虚幻 Actor 标签 | ||
AddAngularImpulse | 向该 Actor 添加角冲量。适用于单次瞬间爆发 | ||
AddImpulse | 向该 Actor 添加冲量。适用于单次瞬间爆发 | ||
| boolean | AttachTo | 将该 Actor 附加到任何其他 Actor 上,可选择附加在特定骨骼处 | |
Detach | 将该 Actor 从其附加的 Actor 上分离 | ||
| table of string | GetActorTags | 获取该 Actor 上的所有虚幻 Actor 标签 | |
| Vector | GetAngularForce | 获取该 Actor 的角外力(由 SetAngularForce() 设置) | |
| table of Base Actor | GetAttachedEntities | 获取附加到该 Actor 的所有 Actor | |
| Base Actor or nil | GetAttachedTo | 获取该 Actor 所附加到的父级 Actor | |
| table | GetBounds | 获取该 Actor 的边界范围 | |
| CollisionType | GetCollision | 获取该 Actor 的碰撞类型 | |
| integer | GetDimension | 获取该 Actor 的维度 | |
| float | GetDistanceFromCamera | 获取该 Actor 距离相机的距离 | |
| Vector | GetForce | 获取该 Actor 的持续外力(由 SetForce() 设置) | |
| Vector | GetLocation | 获取该 Actor 在游戏世界中的位置 | |
| Player or nil | GetNetworkAuthority | 获取该 Actor 的网络主控玩家 | |
| Vector | GetRelativeLocation | 如果该 Actor 已附加,获取其相对位置 | |
| Rotator | GetRelativeRotation | 如果该 Actor 已附加,获取其相对旋转 | |
| Rotator | GetRotation | 获取该 Actor 在游戏世界中的角度值 | |
| Vector | GetScale | 获取该 Actor 的缩放比例 | |
| float | GetScreenPercentage | 获取该 Actor 在屏幕中所占尺寸的百分比 | |
| table | GetSocketTransform | 在给定骨骼或插槽名称的情况下,获取世界空间中的插槽变换 | |
| Vector | GetVelocity | 获取该 Actor 当前的速度 | |
| boolean | HasNetworkAuthority | 如果本地玩家当前是该 Actor 的网络主控(Network Authority),则返回 true | |
| boolean | IsGravityEnabled | 如果该 Actor 启用了重力,则返回 true | |
| boolean | IsInWater | 如果该 Actor 处于水中,则返回 true | |
| boolean | IsNetworkDistributed | 如果该 Actor 当前处于网络分配状态,则返回 true | |
| boolean | IsVisible | 如果该 Actor 可见,则返回 true | |
RemoveActorTag | 从该 Actor 中移除一个虚幻 Actor 标签 | ||
RotateTo | 在一定时间内平滑旋转该 Actor 到指定角度 | ||
SetAngularForce | 向该 Actor 添加一个永久的角外力,设为 Vector(0, 0, 0) 可以取消 | ||
SetCastShadow | 设置该 Actor 是否投射阴影 | ||
SetCollision | 设置该 Actor 的碰撞类型 | ||
SetDimension | 设置该 Actor 的维度 | ||
SetDistanceOptimizationMultiplier | 设置此 Actor 的距离优化系数 | ||
SetForce | 向该 Actor 添加一个永久的外力,设为 Vector(0, 0, 0) 可以取消 | ||
SetGravityEnabled | 设置该 Actor 是否启用重力 | ||
SetHighlightEnabled | 设置该 Actor 是否启用高亮显示,以及使用哪个高亮索引值 | ||
SetLifeSpan | 设置该 Actor 被销毁前的生存时间(秒)。经过这段时间后,Actor 将被自动销毁。 | ||
SetLocation | 设置该 Actor 在游戏世界中的位置 | ||
SetNetworkAuthority | 设置某个玩家拥有此 Actor 的网络主控 | ||
SetNetworkAuthorityAutoDistributed | 设置该 Actor 是否在玩家之间自动分配网络主控 | ||
SetOutlineEnabled | 设置该 Actor 是否启用轮廓线描边,以及使用哪个轮廓线索引值 | ||
SetRelativeLocation | 在本地空间中设置该 Actor 的相对位置(仅在此 Actor 已附加时生效) | ||
SetRelativeRotation | 在本地空间中设置该 Actor 的相对旋转(仅在此 Actor 已附加时生效) | ||
SetRenderCullDistance | 设置该 Actor 的渲染剔除距离 | ||
SetRotation | 设置该 Actor 在游戏世界中的旋转 | ||
SetScale | 设置该 Actor 的缩放比例 | ||
SetVisibility | 设置该 Actor 是否可见 | ||
TranslateTo | 在一定时间内平滑地将该 Actor 移动到某个位置 | ||
| boolean | WasRecentlyRendered | 获取该 Actor 最近是否在屏幕上被渲染过 |
Inherited Paintable Functions
Base Paintablescripting-reference/classes/base-classes/paintable
| Returns | Name | Description | |
|---|---|---|---|
| Color | GetMaterialColorParameter | 从该 Actor 的材质中获取 Color 参数 | |
| float | GetMaterialScalarParameter | 从该 Actor 的材质中获取 Scalar 参数 | |
| string | GetMaterialTextureParameter | 从该 Actor 的材质中获取 Texture 参数 | |
| Vector | GetMaterialVectorParameter | 从该 Actor 的材质中获取 Vector 参数 | |
ResetMaterial | 将指定索引处的材质重置为原始材质 | ||
SetMaterial | 设置该 Actor 指定索引处的材质 | ||
SetMaterialColorParameter | 设置该 Actor 材质中的 Color 参数 | ||
SetMaterialFromCanvas | 将该 Actor 指定索引处的材质设为 Canvas 对象 | ||
SetMaterialFromSceneCapture | 将该 Actor 指定索引处的材质设为 SceneCapture 对象 | ||
SetMaterialFromWebUI | 将该 Actor 指定索引处的材质设为 WebUI 对象 | ||
SetMaterialScalarParameter | 设置该 Actor 材质中的 Scalar 参数 | ||
SetMaterialTextureParameter | 将该 Actor 材质中的纹理参数设为一张图像 | ||
SetMaterialVectorParameter | 设置该 Actor 材质中的 Vector 参数 | ||
SetPhysicalMaterial | 使用新的物理材质覆盖该 Actor 的物理材质 |
| Returns | Name | Description | |
|---|---|---|---|
| integer | AddInstance | 向此组件添加一个实例 | |
AddInstances | 向此组件添加多个实例。调用此函数一次比多次调用 AddInstance 的效率高得多 | ||
ClearInstances | 移除所有实例。 | ||
| integer | GetInstanceCount | 返回当前存储的实例数量 | |
| Vector, Rotator, Vector | GetInstanceTransform | 返回指定索引处实例的当前变换 | |
| StaticMesh Reference | GetMesh | 获取所使用的资产路径网格体 | |
RemoveInstance | 移除指定索引处的实例。这会将最后一个元素移动到提供的索引处,并将计数减少 1 | ||
SetInstanceTransform | 更改现有实例的变换。你可以将其他所有参数传入 nil,以便仅修改单个属性 |

AddInstance
向此组件添加一个实例
local index = my_instancedstaticmesh:AddInstance(relative_location, relative_rotation?, scale?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| Vector | relative_location | Required parameter | No description provided |
| Rotator | relative_rotation? | Rotator(0, 0, 0) | No description provided |
| Vector | scale? | Vector(1, 1, 1) | No description provided |
Returns
| Type | Description |
|---|---|
| integer | 新添加实例的索引 |

AddInstances
向此组件添加多个实例。调用此函数一次比多次调用 AddInstance 的效率高得多
my_instancedstaticmesh:AddInstances(instances)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| table | instances | Required parameter | 包含实例的数组 with this format |

ClearInstances
移除所有实例。
my_instancedstaticmesh:ClearInstances()

GetInstanceCount
返回当前存储的实例数量
local count = my_instancedstaticmesh:GetInstanceCount()
Returns
| Type | Description |
|---|---|
| integer | count |

GetInstanceTransform
返回指定索引处实例的当前变换
local relative_location, relative_rotation, scale = my_instancedstaticmesh:GetInstanceTransform(index)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | index | Required parameter | No description provided |
See also SetInstanceTransform.

GetMesh
获取所使用的资产路径网格体
local static_mesh_asset = my_instancedstaticmesh:GetMesh()
Returns
| Type | Description |
|---|---|
| StaticMesh Reference | static_mesh_asset |

RemoveInstance
移除指定索引处的实例。这会将最后一个元素移动到提供的索引处,并将计数减少 1
my_instancedstaticmesh:RemoveInstance(index)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | index | Required parameter | No description provided |

SetInstanceTransform
更改现有实例的变换。你可以将其他所有参数传入 nil,以便仅修改单个属性
my_instancedstaticmesh:SetInstanceTransform(index, relative_location?, relative_rotation?, scale?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| integer | index | Required parameter | No description provided |
| Vector | relative_location? | (current location) | No description provided |
| Rotator | relative_rotation? | (current rotation) | No description provided |
| Vector | scale? | (current scale) | No description provided |
See also GetInstanceTransform.
🚀 事件
Inherited Entity Events
Base Entityscripting-reference/classes/base-classes/entity
| Name | Description | |
|---|---|---|
ClassRegister | 当使用 继承系统 注册一个新类时触发 | |
Destroy | 当实体被销毁时触发 | |
Spawn | 当实体被生成/创建时触发 | |
ValueChange | 当实体通过 :SetValue() 改变了值时触发 |
Inherited Actor Events
Base Actorscripting-reference/classes/base-classes/actor
| Name | Description | |
|---|---|---|
DimensionChange | Triggered when an Actor changes its dimension |
This class doesn't have own events.