Search Unity

Bug Issue having Netcode for entities (1.0.17) in project (code completion issue?)

Discussion in 'NetCode for ECS' started by MJBarr, Jan 26, 2024.

  1. MJBarr

    MJBarr

    Joined:
    Aug 27, 2015
    Posts:
    1
    I have been delving into ECS these last few weeks and noticed something really strange when trying to get a bullet instantiator working using a SystemBase as a bridge to set component values. Apparently, just having the Netcode for Entities package installed (v 1.0.17) was causing odd things to happen, with no relevant error messages as well.

    Can see the issue here: https://imgur.com/a/GAZNAhR
    What happens: having no call to a value set by the systembase spawns bullets every frame just fine, and they contact and destroy on contact with a zombie (target), but leave the particle renderer.

    Adding back in the value check causes bullets to spawn without the associated model (sphere) but still spawns the particle entity: on contact with the target, the target entity is destroyed in the editor window (and no further trails will contact the entity either, not shown) but the entity remains active and moving.

    Basically, weird entity creation/cleanup issues.

    Removing the netcode package fixes this issue completely: bullets plus the particle renderer spawn, move, contact target, and destroy both the bullet + particle renderer and the target. No netcode calls are used anywhere in the project by me.

    Using: Entities 1.0.16, Entities Graphics 1.0.16, Netcode for Entities 1.0.17

    Project file available on request.
     
  2. CMarastoni

    CMarastoni

    Unity Technologies

    Joined:
    Mar 18, 2020
    Posts:
    894
    When you add Netcode, by default two worlds are created: A client and a server world. All your systems, unless marked via WorldSystemFilter to run on a specific system, will be added to both world and entities (in case) spawned in their respective world.
    So, unless entities are created only by the server or the client you may have two entities (and gameobject too if they have any companion).

    The server does not have a presentation group, and don't render entities data, but gameobject and particles are rendered if they are created by spawning an entity.
    Clients did present and render both entity and gameobject.

    So, obviously that will not work by default with Netcode. In order to have the same behaviour you need to re-write the bootstrap to disable creating multiple world. For example:

    Code (csharp):
    1.  
    2. [UnityEngine.Scripting.Preserve]
    3. // The bootstrap needs to extend `ClientServerBootstrap`, there can only be one class extending it in the project.
    4. public class FrontendBootstrap : ClientServerBootstrap
    5. {
    6.     public override bool Initialize(string defaultWorldName)
    7.     {      
    8.           CreateLocalWorld(defaultWorldName); // Don't create the Client & Server worlds
    9.           return true;
    10.     }
    11. }
    12.  
    13.