Skip to content

Commit 6479fbd

Browse files
author
rain
committed
docs: clarify Unreal connection ticking
1 parent 4b46617 commit 6479fbd

2 files changed

Lines changed: 52 additions & 5 deletions

File tree

docs/docs/00200-core-concepts/00600-clients/00300-connection.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,9 @@ The token is sent to the server during connection and validates your identity. S
174174
175175
:::danger[Critical: C#, Unity, and Unreal Users]
176176
177-
In C# (including Unity) and Unreal Engine, you **must** manually advance the connection to process incoming messages. The connection does not process messages automatically!
177+
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.
178178
179-
Call `DbConnection.FrameTick()` in your game loop or update method:
179+
Call `FrameTick()` in your game loop or update method:
180180
181181
<Tabs groupId="client-language" queryString>
182182
<TabItem value="csharp" label="C#">
@@ -200,7 +200,7 @@ while (running)
200200
<TabItem value="unreal" label="Unreal">
201201

202202
```cpp
203-
// In your Actor's Tick() method
203+
// Option 1: call FrameTick() from your Actor's Tick() method
204204
void AMyActor::Tick(float DeltaTime)
205205
{
206206
Super::Tick(DeltaTime);
@@ -210,6 +210,10 @@ void AMyActor::Tick(float DeltaTime)
210210
Conn->FrameTick();
211211
}
212212
}
213+
214+
// Option 2: enable automatic ticking once after building the connection
215+
Conn = Builder->Build();
216+
Conn->SetAutoTicking(true);
213217
```
214218
215219
</TabItem>

docs/docs/00200-core-concepts/00600-clients/00800-unreal-reference.md

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ A connection to a remote database is represented by the `UDbConnection` class. T
5858
| Name | Description |
5959
| ---------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
6060
| [Connect to a database](#connect-to-a-database) | Construct a UDbConnection instance. |
61-
| [Advance the connection](#advance-the-connection-and-process-messages) | The connection processes messages automatically via WebSocket callbacks. |
61+
| [Advance the connection](#advance-the-connection-and-process-messages) | Process queued messages with `FrameTick` or automatic ticking. |
6262
| [Access tables and reducers](#access-tables-and-reducers) | Access the client cache, request reducer invocations, and register callbacks. |
6363

6464
### Connect to a database
@@ -186,7 +186,50 @@ Finalize configuration and open the connection. This creates a WebSocket connect
186186
187187
### Advance the connection and process messages
188188
189-
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.
189+
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.
190+
191+
You can either call `FrameTick()` yourself from an Actor or component tick, or enable the SDK's automatic ticker once after building the connection:
192+
193+
```cpp
194+
void AGameManager::Tick(float DeltaTime)
195+
{
196+
Super::Tick(DeltaTime);
197+
198+
if (Conn && Conn->IsActive())
199+
{
200+
Conn->FrameTick();
201+
}
202+
}
203+
```
204+
205+
```cpp
206+
Conn = Builder->Build();
207+
Conn->SetAutoTicking(true);
208+
```
209+
210+
#### Method `FrameTick`
211+
212+
```cpp
213+
class UDbConnection
214+
{
215+
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
216+
void FrameTick();
217+
};
218+
```
219+
220+
Process any queued server messages and dispatch the corresponding callbacks. Call this regularly from game-thread code if you manage ticking yourself.
221+
222+
#### Method `SetAutoTicking`
223+
224+
```cpp
225+
class UDbConnection
226+
{
227+
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
228+
void SetAutoTicking(bool bAutoTick);
229+
};
230+
```
231+
232+
Enable or disable the SDK's automatic ticker. When enabled, the connection registers with Unreal's core ticker and calls `FrameTick()` for you.
190233
191234
### Access tables and reducers
192235

0 commit comments

Comments
 (0)