Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

유휴 (Idle) 상태와 물리 프로세싱

Games run in a loop. Each frame, you need to update the state of your game world before drawing it on screen. Godot provides two virtual methods in the Node class to do so: Node._process() and Node._physics_process(). If you define either or both in a script, the engine will call them automatically.

사용할 수 있는 프로세싱 타입은 두 가지가 있습니다:

  1. **Idle processing**(유휴상태 프로세싱) 은 모든 프레임마다 노드를 가능한 한 자주 업데이트하는 코드를 실행하게 해줍니다.

  2. Physics processing (물리 프로세싱) 은 기본적으로 1초 당 60회를 고정된 속도로 처리합니다. 이는 게임의 실제 프레임 속도와는 별개이며, 물리 (physics)를 매끄럽게 진행하도록 유지합니다. 움직이는 몸이 환경에 충돌하는 것처럼, 물리 엔진과 관련된 모든 것에 대해 물리 프로세싱을 사용해야 합니다.

스크립트에서 Node._process()메서드를 정의하여 유휴 프로세싱을 활성화 할 수 있습니다. :ref:`Node.set_process() <class_Node_method_set_process>`를 호출하여 이 기능을 끄고 킬 수 있습니다.

엔진은 프레임을 그릴 때 마다 이 메서드를 호출합니다:

func _process(delta):
    # Do something...
    pass

Keep in mind that the frequency at which the engine calls _process() depends on your application's framerate, which varies over time and across devices.

The function's delta parameter is the time elapsed in seconds since the previous call to _process(). Use this parameter to make calculations independent of the framerate. For example, you should always multiply a speed value by delta to animate a moving object.

Physics processing works with a similar virtual function: _physics_process(). Use it for calculations that must happen before each physics step, like moving a character that collides with the game world. As mentioned above, _physics_process() runs at fixed time intervals as much as possible to keep the physics interactions stable. You can change the interval between physics steps in the Project Settings, under Physics -> Common -> Physics Fps. By default, it's set to run 60 times per second.

The engine calls this method before every physics step:

func _physics_process(delta):
    # Do something...
    pass

The function _process() is not synchronized with physics. Its rate depends on hardware and game optimization. It also runs after the physics step in single-threaded games.

You can see the _process() function at work by creating a scene with a single Label node, with the following script attached to it:

extends Label

var time = 0

func _process(delta):
    time += delta
    text = str(time) # 'text' is a built-in Label property.

When you run the scene, you should see a counter increasing each frame.