RunServiceクラス
ひとことで言うと
ゲームの1フレームごとに処理を実行するためのサービスです。パーツを回し続けるなど、なめらかに動かし続けたいときに使います。
公式の説明(英語):Service responsible for all runtime activity and progression of time.
使用例
local RunService = game:GetService("RunService")
local part = script.Parent :: BasePart
part.Anchored = true
RunService.Heartbeat:Connect(function(deltaTime)
part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(90) * deltaTime, 0)
end)スクリプトは、Luauの型チェック(luau-lsp)で確認しています。
クラスの関係
プロパティ(1)
| 名前と書き方 | 説明 |
|---|---|
RunStateRunService.RunState: RunState | The current run state of the game's simulation. |
メソッド(18)
| 名前と書き方 | 説明 |
|---|---|
BindToAnimationRunService:BindToAnimation(function: Function, frequency: StepFrequency, priority: int): RBXScriptConnection | Binds a custom function to be called at a fixed frequency before Animators update when fixed simulation is enabled, or immediately before BindToSimulation callbacks otherwise. |
BindToAnimationParallelRunService:BindToAnimationParallel(function: Function, frequency: StepFrequency, priority: int): RBXScriptConnection | Binds an Actor-scoped function to run in parallel at a fixed frequency after serial Class.RunService:BindToAnimation()|BindToAnimation() callbacks. |
BindToRenderStepRunService:BindToRenderStep(name: string, priority: int, function: Function): () | Given a string name of a function and a priority, this method binds the function to RunService.PreRender. |
BindToSimulationRunService:BindToSimulation(function: Function, frequency: StepFrequency, priority: int): RBXScriptConnection | Binds a custom function to be called at a fixed frequency which is independent of the frame rate. |
BindToSimulationParallelRunService:BindToSimulationParallel(function: Function, frequency: StepFrequency, priority: int): RBXScriptConnection | Binds an Actor-scoped function to run in parallel at a fixed frequency after serial Class.RunService:BindToSimulation()|BindToSimulation() callbacks. |
GetPredictionStatusRunService:GetPredictionStatus(context: Instance): PredictionStatus | Checks the PredictionStatus of a specific context instance, useful for debugging scripts affecting multiple instances where some might be predicted and others might not. |
IsClientRunService:IsClient(): boolean | クライアントで実行されているかを調べます。Returns whether the current environment is running on the client. |
IsEditRunService:IsEdit(): boolean | Returns whether the current environment is in Edit mode. |
IsResimulatingRunService:IsResimulating(): boolean | Returns whether the client is currently in a resimulation step after a misprediction in the server authority model. |
IsRunModeRunService:IsRunMode(): boolean | Returns whether a **Run** playtest has been initiated in Studio. |
IsRunningRunService:IsRunning(): boolean | Returns whether the experience is currently running. |
IsServerRunService:IsServer(): boolean | サーバーで実行されているかを調べます。Returns whether the current environment is running on the server. |
IsStudioRunService:IsStudio(): boolean | Returns whether the current environment is running in Studio. |
PauseRunService:Pause(): () | Pauses the experience's simulation if it is running, suspending physics and scripts. |
RunRunService:Run(): () | Runs the game's simulation, running physics and scripts. |
SetPredictionModeRunService:SetPredictionMode(context: Instance, mode: PredictionMode): () | Sets the prediction mode for an Instance to an PredictionMode value. |
StopRunService:Stop(): () | Stops the experience's simulation if it is running. |
UnbindFromRenderStepRunService:UnbindFromRenderStep(name: string): () | Unbinds a function that was bound to the render loop using Class.RunService:BindToRenderStep(). |
イベント(9)
| 名前と書き方 | 説明 |
|---|---|
HeartbeatRunService.Heartbeat(deltaTime: double) | 毎フレーム、物理の計算のあとに発生するイベントです。前のフレームからの経過時間(秒)が渡されます。Fires every frame, after the physics simulation has completed. |
MispredictionRunService.Misprediction(time: double, instances: Array, stats: Dictionary) | In the server authority model, fires during prediction when the engine detects that the client has diverged from the server's authoritative state. Intended for plugin-based debugging. |
PostSimulationRunService.PostSimulation(deltaTimeSim: double) | Fires every frame, after the physics simulation has completed. |
PreAnimationRunService.PreAnimation(deltaTimeSim: double) | Fires every frame, prior to the physics simulation but after rendering. |
PreRenderRunService.PreRender(deltaTimeRender: double) | Fires every frame, prior to the frame being rendered. |
PreSimulationRunService.PreSimulation(deltaTimeSim: double) | Fires every frame, prior to the physics simulation. |
RenderSteppedRunService.RenderStepped(deltaTime: double) | 毎フレーム、画面を描く前に発生するイベントです(LocalScript専用)。Fires every frame, prior to the frame being rendered. |
RollbackRunService.Rollback(time: double) | In the server authority model, this fires after rolling back the predicted state due to a misprediction, but before resimulation begins. |
SteppedRunService.Stepped(time: double, deltaTime: double) | Fires every frame, prior to the physics simulation. |
受け継いでいるメンバー
Instance から受け継いでいるもの(46)
Archivable・Capabilities・IsInSandbox・Name・Parent・PredictionMode・Sandboxed・AddTag・ClearAllChildren・Clone・Destroy・FindFirstAncestor・FindFirstAncestorOfClass・FindFirstAncestorWhichIsA・FindFirstChild・FindFirstChildOfClass・FindFirstChildWhichIsA・FindFirstDescendant・GetActor・GetAttribute・GetAttributeChangedSignal・GetAttributes・GetChildren・GetDebugId・GetDescendants・GetFullName・GetStyled・GetStyledPropertyChangedSignal・GetTags・HasTag・IsAncestorOf・IsDescendantOf・IsPropertyModified・QueryDescendants・RemoveTag・ResetPropertyToDefault・SetAttribute・WaitForChild・AncestryChanged・AttributeChanged・ChildAdded・ChildRemoved・DescendantAdded・DescendantRemoving・Destroying・StyledPropertiesChanged
Object から受け継いでいるもの(4)
RunServiceを使う記事
英語の説明とメンバーの一覧は、Roblox Creator Documentation(RunService)をもとにしています(CC BY 4.0)。日本語の解説は、このサイトで独自に書いたものです。