Content Patcher

Content Patcher

463k Downloads

[Content Patcher] Patch with custom token not applying when setting IsReady = true too late.

DeLiXx opened this issue ยท 1 comments

commented

Regarding the discord message earlier.

Architecture:

  • Host needs to process data on DayStarted and shares data with client afterwards
  • Custom Token requires host data to be accessed.
  • Custom Token validates with IsReady = false and UpdateContext = false until data is received
  • Once data is received by client, IsReady will be true until DayEnding
  • Once data is received UpdateContext will return true exactly once

Expected behaviour:

  • Any changes relying on Custom Token will not apply until Custom Token is ready.
  • Once Custom Token returns IsReady = true and UpdateContext returns true the changes relying on Custom Token will try to apply

Actual behaviour:

  • The example patch is never applied to the client from the second day of joining onwards
  • patch summary shows that the patch did not apply, because Custom Token is not ready
  • patch parse says Custom Token is ready, valid and returns expected value of -1

Reproduce:

  1. Download and install the minimum reproducible example
  2. Open SDV twice
  3. Host the Standard farm on instance 1
  4. Join the game with blank IP on instance 2
  5. Leave the house and cabin with both players.
  6. Observe existence of a construction map patch for both players
  7. Go to sleep
  8. Leave house again
  9. Observe missing existence of a construction map patch for client only

Host Log

Client Log

grafik

Minimal reproducible example:
CustomTokenBug.zip

Source Code of example:
SDVTest.zip

Sidenotes:

  • I spawned a bed in the screenshot using Unlockable Bundles ub bed command to make testing easier.
    This does not change the observed behaviour.
  • Setting a breakpoint inside: CustomToken -> UpdateContext -> inside if shows, that ContentPatcher is checking if it should update the context, but it never does, even though UpdateContext and IsReady both return true.
commented

Hi! Custom tokens using the advanced API are tricky, since there's complexities that Content Patcher normally handles for you.

In particular, readiness is more nuanced under the hood than it may seem. There isn't really a single context or context update; there's a hierarchy of contexts which are updated based on their update rate. For example, an OnTimeChange context update won't affect a patch with the default OnDayStarted update rate; in that case the patch will continue using the values from its last context update (i.e. day start) until its next one.

The behavior you're seeing is likely:

  1. The main context update happens, but your token isn't ready yet.
  2. Your token becomes ready.
  3. The affected patches aren't reloaded until their update rate is triggered (default OnDayStart).

In other words, the token must be ready when the patch updates its context. This is a bit complex from the token side, since it's optimized for simplicity on the patch side. So if a token needs to work consistently, it should generally be ready:

  • For the main player, before the game has loaded SaveGame.loaded into the game world.
  • For a farmhand, probably right after the host context message is received before it starts loading stuff into the game world.