Search Unity

Resolved Baking and Client or Server World Specific Baked Components

Discussion in 'DOTS Dev Blitz Day 2022 - Q&A' started by Kmsxkuse, Dec 8, 2022.

  1. Kmsxkuse

    Kmsxkuse

    Joined:
    Feb 15, 2019
    Posts:
    306
    I see that there is currently IsClient() and IsServer() methods in the baking override yet, from what I can tell, they do not work in the editor.

    Are they runtime only API? How could we test in editor if the baking works then?
     
  2. NikiWalker

    NikiWalker

    Unity Technologies

    Joined:
    May 18, 2021
    Posts:
    316
    This sounds like a bug in Baking. A simple repro would be very much appreciated.

    Baking does not depend on playmode state. I.e. It's a separate process that happens in-editor, whenever your sub-scene or prefab changes.

    We'll look into this, and I'll put a reminder in JIRA to reply to this thread when fixed. Thanks for the report.

    EDIT: Oh, which version are you on, please?

    The simplest thing is to throw a `Debug.Log` or breakpoint into your baker. It should give you some context around when bakers are triggered.
     
    Kmsxkuse likes this.
  3. Kmsxkuse

    Kmsxkuse

    Joined:
    Feb 15, 2019
    Posts:
    306
    1.0 Pre.15

    I'm pretty sure the IsClient() and IsServer() relies on "(_State.World.Flags&WorldFlags.GameClient) == WorldFlags.GameClient;"

    But the world flag for baking is always BakingWorld. Client and Server are only set once playmode is entered.
     
  4. NikiWalker

    NikiWalker

    Unity Technologies

    Joined:
    May 18, 2021
    Posts:
    316
    Ah, then yeah it's entirely unusable for your purposes.
    An alternative is to use the `GhostAuthoringInspectionComponent` to disable specific components on the client/server (via the buttons there).
     
    Kmsxkuse likes this.
  5. Kmsxkuse

    Kmsxkuse

    Joined:
    Feb 15, 2019
    Posts:
    306
    I've been doing that along with custom systems that remove non-sync'ed components with a EntityManager.Remove() but I was wondering if it could be done at bake instead of runtime.

    Are there plans to make these IsClient/Server() methods work in editor at bake?
     
  6. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    900
    The baking world is a temporary world that is neither marked as server or client. In order to know it you are targeting a client or server or client/server baking world you need to use the
    GetNetcodeTarget method (extension method) that is returning the correct target to use when converting prefabs and sub-scene in general.
    The IsClient and IsServer method are not retiring the values when baking sub-scenes because the baking world is a temporary one (and two the destination).
    I also remember that there is currently an issue in that sene in 1.0-pre.15 in general with that flow
     
    Kmsxkuse likes this.
  7. Kmsxkuse

    Kmsxkuse

    Joined:
    Feb 15, 2019
    Posts:
    306
    GetNetcodeTarget seems to just query the build target which I guess works but in a client-server build, that would leave server components in the client world and vice versa.
     
  8. optimise

    optimise

    Joined:
    Jan 22, 2014
    Posts:
    2,129
    Yes. Baker at 1.0-pre.15 is buggy that will only trigger NetcodeConversionTarget.ClientAndServer. Expected behavior should be trigger all the NetcodeConversionTarget.Client, NetcodeConversionTarget.Server and NetcodeConversionTarget.ClientAndServer.