Search Unity

com.unity.netcode Getting Started documentation sample issue EnableNetCubeGhostReceiveSystemComponen

Discussion in 'NetCode for ECS' started by Kirkules_, Aug 24, 2020.

  1. Kirkules_

    Kirkules_

    Joined:
    Aug 5, 2014
    Posts:
    65
    I'm attempting to get my first NetCode sample to run and I've run into one issue.. In the unity.netcode getting started section in the SampleCubeInput : ComponentSystem class, there's a line in the OnCreate override: RequireSingletonForUpdate<EnableNetCubeGhostReceiveSystemComponent>(); The EnableNetCubeGhostReceiveSystemComponent type isn't defined, so I assumed it was supposed to be NetCubeReceiveCommandSystem, but when I replace it it throws a runtime exception: ArgumentException: Unknown Type:NetCubeReceiveCommandSystem All ComponentType must be known at compile time. For generic components, each concrete type must be registered with [RegisterGenericComponentType]. When I attempt to use RegisterGenericComponentType it says it's an assembly level attribute.. this doesn't seem like I'm going down the correct path.. help
     
  2. timjohansson

    timjohansson

    Unity Technologies

    Joined:
    Jul 13, 2016
    Posts:
    473
    In netcode 0.2 EnableNetCubeGhostReceiveSystemComponent is generated when you generate the code for the ghost collection. In netcode 0.3 it does not exist and it still being there is a bug in the docs. Unless you have multiple scenes in the project running different games you can delete the RequireSingletonForUpdate, it is only there to stop the system from running in scenes which do not have that specific ghost collection.
     
  3. Enzi

    Enzi

    Joined:
    Jan 28, 2013
    Posts:
    967
  4. Kirkules_

    Kirkules_

    Joined:
    Aug 5, 2014
    Posts:
    65
  5. Kirkules_

    Kirkules_

    Joined:
    Aug 5, 2014
    Posts:
    65
    So I got it all working.. even added Unity.Physics to the MovableCube and the plane, and spawned some NPCMovableCubes and all was working well, the physics, netcodd etc..
    Then I tried to update the Systems to inherit from SystemBase instead of ComponentSystem and all hell broke lose in the simulation. Physics is wack, NetCode is still fine but there are some architectural changes that are required in that EntityManager.GetComponentData can no longer be used inside the ForEach.ScheduleParallel.. The compiler warning says it can be used in .WithoutBoost() and .Run() but I've tried both and it doesn't compile.

    In GoInGameServer OnUpdate, this line is the issue:

    EntityManager.SetComponentData(player, new GhostOwnerComponent { NetworkId = EntityManager.GetComponentData<NetworkIdComponent>(receiveRpcCommandRequest.SourceConnection).Value });

    Not sure what to make of the physics simulation not working anymore, but if I spawned 1600 NPCMovableCube entities with a mass of 1 and one MovableCube player entity with a mass of 100, I could move the the player through the NPCs fairly easily with no problems.. Now, using SystemBase, the simulation goes nuts. If I lower it to 400 NPCs it's still wack. ALSO with SystemBase the physics simulation seems to 'break' exactly 30 seconds in and ALL the NPCs and player cubes are 'deleted' from the world and I have no idea why.. None of these issues happened with deriving from ComponentSystem.

    Update

    I changed all of the ScheduleParallel() to Run() and that has fixed the following issues:
    The NPCs move normally now.
    The NPCs and player don't get deleted from the simulation 30 seconds in.​

    Movement of the player cube still isn't working properly.

    It appears that if in SampleMovableCubeInput the DynamicBuffer<MovableCubeInput> is added to the player's MovableCube, that is what's causing all the MovableCube and NPCMovalbeCube entities to be deleted from the simulation at 30 seconds in...

    if (ghostOwner.NetworkId == localPlayerNetworkId)
    {
    postUpdateCommands.AddBuffer<MovableCubeInput>( entity);
    postUpdateCommands.SetComponent( ctcEntity, new CommandTargetComponent { targetEntity = entity });
    }


    var inputBuffer = EntityManager.GetBuffer<MovableCubeInput>(localInput);
    inputBuffer.AddCommandData(input);
     
    Last edited: Aug 26, 2020
  6. Kirkules_

    Kirkules_

    Joined:
    Aug 5, 2014
    Posts:
    65
    IReckon I will branch multiplayer/samples and work in there while I learn NetCode. I was able to clone It, move what I made into it, and got it working in 15 minutes. I have a feeling my project is corrupted.