Instanceクラス
ひとことで言うと
ロブロックス(Roblox)のすべての部品(パーツ・スクリプト・サービスなど)の元になるクラスです。Instance.new("Part") のようにして、新しい部品を作れます。
公式の説明(英語):Instance is the base class for all classes in the Roblox class hierarchy which can be part of the DataModel tree.
ゲームの中のものは、すべて「インスタンス」です。インスタンスは、親子の階層(エクスプローラーに表示される木の形)になって並んでいます。
Instanceのプロパティやメソッド(Name・Parent・Destroy・FindFirstChild・WaitForChildなど)は、どのクラスでも使える共通の機能です。
使用例
for i = 1, 10 do
local part = Instance.new("Part")
part.Size = Vector3.new(4, 1, 4)
part.Position = Vector3.new(i * 5, 10, 0)
part.Anchored = true
part.BrickColor = BrickColor.random()
part.Parent = workspace
endスクリプトは、Luauの型チェック(luau-lsp)で確認しています。
クラスの関係
受け継いでいるクラス:Object → Instance
このクラスを受け継ぐクラス:AccessoryDescription、Accoutrement、AdPortal、AdService、AdvancedDragger、AnalyticsService、Animation、AnimationClip、AnimationClipProvider、AnimationController、AnimationNodeDefinition、AnimationRigData、AnimationTrack、AnimationValueNodeDefinition、AnimationValueOutputDefinition、Animator、AssetDeliveryProxy、AssetPatchSettings、AssetService、Atmosphere、AudioAnalyzer、AudioChannelMixer、AudioChannelSplitter、AudioChorus、AudioCompressor、AudioDeviceInput、AudioDeviceOutput、AudioDistortion、AudioEcho、AudioEmitter、AudioEqualizer、AudioFader、AudioFilter、AudioFlanger、AudioGate、AudioLimiter、AudioListener、AudioPitchShifter、AudioPlayer、AudioRecorder
プロパティ(7)
| 名前と書き方 | 説明 |
|---|---|
ArchivableInstance.Archivable: boolean | falseにすると、Cloneで複製されず、保存もされません。Determines if an Instance and its descendants can be cloned using Class.Instance:Clone(), and can be saved/published. |
CapabilitiesInstance.Capabilities: SecurityCapabilities | The set of capabilities allowed to be used for scripts inside this container. |
IsInSandboxInstance.IsInSandbox: boolean | Indicates whether the instance is inside a sandboxed container. |
NameInstance.Name: string | インスタンスの名前。エクスプローラーに表示される名前で、スクリプトから探すときにも使います。A non-unique identifier of the Instance. |
ParentInstance.Parent: Instance | 親(ひとつ上の階層)のインスタンス。これを設定すると、そのインスタンスの中に入ります。nilにするとゲームから外れます。Determines the hierarchical parent of the Instance. |
PredictionModeInstance.PredictionMode: PredictionMode | Reflects the client-side prediction mode applied to the instance under server-authoritative physics. |
SandboxedInstance.Sandboxed: boolean | When enabled, the instance can only access abilities in its Capabilities list. |
メソッド(31)
| 名前と書き方 | 説明 |
|---|---|
AddTagInstance:AddTag(tag: string): () | Applies a tag to the instance. |
ClearAllChildrenInstance:ClearAllChildren(): () | This method destroys all of an instance's children. |
CloneInstance:Clone(): Instance | インスタンスを中身ごと複製します。複製したものは、Parentを設定するまでゲームに表示されません。Create a copy of an instance and all its descendants, ignoring instances that are not Class.Instance.Archivable|Archivable. |
DestroyInstance:Destroy(): () | インスタンスを削除します。中に入っているものもまとめて消え、つながっているイベントも切れます。Sets the Instance.Parent property to nil, locks the Instance.Parent property, disconnects all connections, and calls Destroy() on all children. |
FindFirstAncestorInstance:FindFirstAncestor(name: string): Instance? | 指定した名前の祖先(親・親の親…)を探して返します。Returns the first ancestor of the Instance whose Instance.Name is equal to the given name. |
FindFirstAncestorOfClassInstance:FindFirstAncestorOfClass(className: string): Instance? | Returns the first ancestor of the Instance whose Object.ClassName is equal to the given className. |
FindFirstAncestorWhichIsAInstance:FindFirstAncestorWhichIsA(className: string): Instance? | Returns the first ancestor of the Instance for whom Class.Object:IsA() returns true for the given className. |
FindFirstChildInstance:FindFirstChild(name: string, recursive: boolean): Instance? | 指定した名前の子を探して返します。見つからないときはnilを返します。Returns the first child of the Instance found with the given name. |
FindFirstChildOfClassInstance:FindFirstChildOfClass(className: string): Instance? | Returns the first child of the Instance whose Class.Object.ClassName|ClassName is equal to the given class name. |
FindFirstChildWhichIsAInstance:FindFirstChildWhichIsA(className: string, recursive: boolean): Instance? | 指定したクラス(またはその仲間)の子を探して返します。Returns the first child of the Instance for whom Class.Object:IsA() returns true for the given className. |
FindFirstDescendantInstance:FindFirstDescendant(name: string): Instance? | Returns the first descendant found with the given Instance.Name. |
GetActorInstance:GetActor(): Actor? | Returns the Actor associated with the Instance, if any. |
GetAttributeInstance:GetAttribute(attribute: string): Variant | インスタンスに付けた属性(アトリビュート)の値を取り出します。Returns the value which has been assigned to the given attribute name. |
GetAttributeChangedSignalInstance:GetAttributeChangedSignal(attribute: string): RBXScriptSignal | Returns an event that fires when the given attribute changes. |
GetAttributesInstance:GetAttributes(): Dictionary | Returns a dictionary of the instance's attributes. |
GetChildrenInstance:GetChildren(): Instances | 子をすべて配列(テーブル)で返します。Returns an array containing all of the instance's children. |
GetDebugIdInstance:GetDebugId(scopeLength: int): string | Returns a coded string of the debug ID used internally by Roblox. |
GetDescendantsInstance:GetDescendants(): Instances | 子・孫・ひ孫…をすべて配列で返します。Returns an array containing all of the descendants of the instance. |
GetFullNameInstance:GetFullName(): string | Returns a string describing the instance's ancestry. |
GetStyledInstance:GetStyled(name: string, selector: string?): Variant | Returns the styled or explicitly modified value of the specified property, or else the default property value if it hasn't been styled/modified. |
GetStyledPropertyChangedSignalInstance:GetStyledPropertyChangedSignal(property: string): RBXScriptSignal | Returns an event that fires when the given style property changes on the instance. |
GetTagsInstance:GetTags(): Array | Gets an array of all tags applied to the instance. |
HasTagInstance:HasTag(tag: string): boolean | Check whether the instance has a given tag. |
IsAncestorOfInstance:IsAncestorOf(descendant: Instance): boolean | Returns true if an Instance is an ancestor of the given descendant. |
IsDescendantOfInstance:IsDescendantOf(ancestor: Instance): boolean | 指定したインスタンスの中に入っているかを調べます。Returns true if an Instance is a descendant of the given ancestor. |
IsPropertyModifiedInstance:IsPropertyModified(property: string): boolean | Returns true if the value stored in the specified property is not equal to the code-instantiated default. |
QueryDescendantsInstance:QueryDescendants(selector: string): Instances | Returns an array containing all descendants of the instance that match the selector string. |
RemoveTagInstance:RemoveTag(tag: string): () | Removes a tag from the instance. |
ResetPropertyToDefaultInstance:ResetPropertyToDefault(property: string): () | Resets a property to its default value. |
SetAttributeInstance:SetAttribute(attribute: string, value: Variant): () | インスタンスに属性(アトリビュート)を付けます。自分で決めた名前で値を保存できます。Sets the attribute with the given name to the given value. |
WaitForChildInstance:WaitForChild(childName: string, timeOut: double): Instance | 指定した名前の子が現れるまで待ってから返します。LocalScriptで、まだ読み込まれていないものを使うときに必須です。Returns the child of the Instance with the given name. If the child does not exist, it will yield the current thread until it does. |
イベント(8)
| 名前と書き方 | 説明 |
|---|---|
AncestryChangedInstance.AncestryChanged(child: Instance, parent: Instance) | Fires when the Instance.Parent property of this object or one of its ancestors is changed. |
AttributeChangedInstance.AttributeChanged(attribute: string) | Fires whenever an attribute is changed on the Instance. |
ChildAddedInstance.ChildAdded(child: Instance) | 子が追加されたときに発生するイベントです。Fires after an object is parented to this Instance. |
ChildRemovedInstance.ChildRemoved(child: Instance) | 子が取り除かれたときに発生するイベントです。Fires after a child is removed from this Instance. |
DescendantAddedInstance.DescendantAdded(descendant: Instance) | Fires after a descendant is added to the Instance. |
DescendantRemovingInstance.DescendantRemoving(descendant: Instance) | Fires immediately before a descendant of the Instance is removed. |
DestroyingInstance.Destroying() | インスタンスが削除される直前に発生するイベントです。Fires immediately before (or is deferred until after) the instance is destroyed via Class.Instance:Destroy(). |
StyledPropertiesChangedInstance.StyledPropertiesChanged() | Fires whenever any style property is changed on the instance, including when a property is set to nil. |
受け継いでいるメンバー
Object から受け継いでいるもの(4)
Instanceを使う記事
英語の説明とメンバーの一覧は、Roblox Creator Documentation(Instance)をもとにしています(CC BY 4.0)。日本語の解説は、このサイトで独自に書いたものです。