Search Unity

Instantiate with ConvertToClientServerEntity & ConvertToEntity

Discussion in 'Data Oriented Technology Stack' started by Jawsarn, Jan 10, 2020.

  1. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    81
    It seems both of the convert options doens't work with Instantiate during in Client/SErver world, as the conversionSystem only resides in default world.

    Workaround
    Code (CSharp):
    1.             var world = World.DefaultGameObjectInjectionWorld;
    2.             World.DefaultGameObjectInjectionWorld = World.AllWorlds[0];
    3.             var cameraObject = Object.Instantiate(m_settings.m_characterCamera);
    4.             World.DefaultGameObjectInjectionWorld = world;
    But not sure how safe it is to assume index 0 is default.

    Will/is there be a better way, or when will we get Camera as Entity?
     
  2. Flipps

    Flipps

    Joined:
    Jul 30, 2019
    Posts:
    32
    Hey Jaws,

    did you add the Authoring Component "ConvertToClientServerEntity" instead of "ConvertToEntity"?

    It works for me with ConvertToClientServerEntity.
     
  3. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    81
    It only works with "ConvertToClientServerEntity" with the code I posted before. Only having the component doesn't solve it, since the current DefaultGameObjectInjectionWorld has to be the default world, since the ConversionSystem isn't included in client and server worlds.
     
  4. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    125
    The problem is that we are currently in the netcode setting World.Active to the currently executing world to work around issues with other code using it incorrectly. This has a side effect of also changing DefaultGameObjectInjectionWorld. We will stop doing that soon and when we do your workaround will no longer be required.
     
    Jawsarn likes this.
unityunity