diff --git a/docs/docs/00200-core-concepts/00600-clients/00300-connection.md b/docs/docs/00200-core-concepts/00600-clients/00300-connection.md index 270d6901570..c2be3160eb6 100644 --- a/docs/docs/00200-core-concepts/00600-clients/00300-connection.md +++ b/docs/docs/00200-core-concepts/00600-clients/00300-connection.md @@ -174,9 +174,9 @@ The token is sent to the server during connection and validates your identity. S :::danger[Critical: C#, Unity, and Unreal Users] -In C# (including Unity) and Unreal Engine, you **must** manually advance the connection to process incoming messages. The connection does not process messages automatically! +In C# (including Unity), you **must** manually advance the connection to process incoming messages. In Unreal Engine, you must either manually advance the connection or enable automatic ticking. If the connection is not advanced, it will not process messages. -Call `DbConnection.FrameTick()` in your game loop or update method: +Call `FrameTick()` in your game loop or update method: @@ -200,7 +200,7 @@ while (running) ```cpp -// In your Actor's Tick() method +// Option 1: call FrameTick() from your Actor's Tick() method void AMyActor::Tick(float DeltaTime) { Super::Tick(DeltaTime); @@ -210,6 +210,10 @@ void AMyActor::Tick(float DeltaTime) Conn->FrameTick(); } } + +// Option 2: enable automatic ticking once after building the connection +Conn = Builder->Build(); +Conn->SetAutoTicking(true); ``` diff --git a/docs/docs/00200-core-concepts/00600-clients/00800-unreal-reference.md b/docs/docs/00200-core-concepts/00600-clients/00800-unreal-reference.md index 906d62f3b0a..0513d4e2139 100644 --- a/docs/docs/00200-core-concepts/00600-clients/00800-unreal-reference.md +++ b/docs/docs/00200-core-concepts/00600-clients/00800-unreal-reference.md @@ -58,7 +58,7 @@ A connection to a remote database is represented by the `UDbConnection` class. T | Name | Description | | ---------------------------------------------------------------------- | ----------------------------------------------------------------------------- | | [Connect to a database](#connect-to-a-database) | Construct a UDbConnection instance. | -| [Advance the connection](#advance-the-connection-and-process-messages) | The connection processes messages automatically via WebSocket callbacks. | +| [Advance the connection](#advance-the-connection-and-process-messages) | Process queued messages with `FrameTick` or automatic ticking. | | [Access tables and reducers](#access-tables-and-reducers) | Access the client cache, request reducer invocations, and register callbacks. | ### Connect to a database @@ -186,7 +186,50 @@ Finalize configuration and open the connection. This creates a WebSocket connect ### Advance the connection and process messages -The Unreal SDK processes messages automatically via WebSocket callbacks and with UDbConnection which ultimately inherits from FTickableGameObject. No manual polling or advancement is required. Events are dispatched through the registered delegates. +The Unreal SDK queues network messages and applies them to the generated client cache on tick. If you do not arrange for the connection to tick, table callbacks, reducer callbacks, and subscription callbacks will not be dispatched. + +You can either call `FrameTick()` yourself from an Actor or component tick, or enable the SDK's automatic ticker once after building the connection: + +```cpp +void AGameManager::Tick(float DeltaTime) +{ + Super::Tick(DeltaTime); + + if (Conn && Conn->IsActive()) + { + Conn->FrameTick(); + } +} +``` + +```cpp +Conn = Builder->Build(); +Conn->SetAutoTicking(true); +``` + +#### Method `FrameTick` + +```cpp +class UDbConnection +{ + UFUNCTION(BlueprintCallable, Category = "SpacetimeDB") + void FrameTick(); +}; +``` + +Process any queued server messages and dispatch the corresponding callbacks. Call this regularly from game-thread code if you manage ticking yourself. + +#### Method `SetAutoTicking` + +```cpp +class UDbConnection +{ + UFUNCTION(BlueprintCallable, Category = "SpacetimeDB") + void SetAutoTicking(bool bAutoTick); +}; +``` + +Enable or disable the SDK's automatic ticker. When enabled, the connection registers with Unreal's core ticker and calls `FrameTick()` for you. ### Access tables and reducers