#I'm following this official tutorial about netcode for entities
1 messages · Page 1 of 1 (latest)
Post you code here. You should be able to CubeMovementSystem in the editor to see what's running on it
using Unity.Burst;
using Unity.Entities;
using Unity.NetCode;
using UnityEngine;
public struct CubeInput : IInputComponentData
{
public int Horizontal;
public int Vertical;
public void OnStart()
{
Debug.Log("A");
}
}
[DisallowMultipleComponent]
public class CubeInputAuthoring : MonoBehaviour
{
class CubeInputBaking : Unity.Entities.Baker<CubeInputAuthoring>
{
public override void Bake(CubeInputAuthoring authoring)
{
Debug.Log("B");
var entity = GetEntity(TransformUsageFlags.Dynamic);
AddComponent<CubeInput>(entity);
}
}
}
[UpdateInGroup(typeof(GhostInputSystemGroup))]
public partial struct SampleCubeInput : ISystem
{
public void OnCreate(ref SystemState state)
{
Debug.Log("C");
state.RequireForUpdate<NetworkStreamInGame>();
state.RequireForUpdate<CubeSpawner>();
}
public void OnUpdate(ref SystemState state)
{
Debug.Log("D");
foreach (var playerInput in SystemAPI.Query<RefRW<CubeInput>>().WithAll<GhostOwnerIsLocal>())
{
playerInput.ValueRW = default;
if (Input.GetKey("left"))
playerInput.ValueRW.Horizontal -= 1;
if (Input.GetKey("right"))
playerInput.ValueRW.Horizontal += 1;
if (Input.GetKey("down"))
playerInput.ValueRW.Vertical -= 1;
if (Input.GetKey("up"))
playerInput.ValueRW.Vertical += 1;
}
}
}
Or maybe you want as a file ?
Do you also have CubeMovementSystem?
Yes, here it is
using Unity.Entities;
using Unity.Mathematics;
using Unity.NetCode;
using Unity.Transforms;
using Unity.Burst;
using UnityEngine;
[UpdateInGroup(typeof(PredictedSimulationSystemGroup))]
[BurstCompile]
public partial struct CubeMovementSystem : ISystem
{
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var speed = SystemAPI.Time.DeltaTime * 4;
foreach (var (input, trans) in SystemAPI.Query<RefRO<CubeInput>, RefRW<LocalTransform>>().WithAll<Simulate>())
{
var moveInput = new float2(input.ValueRO.Horizontal, input.ValueRO.Vertical);
moveInput = math.normalizesafe(moveInput) * speed;
trans.ValueRW.Position += new float3(moveInput.x, 0, moveInput.y);
}
}
}
That all should work. You can also check the entity inspector to see if the player cube has the correct components
Nope. As long as Cube has CubeInput and LocalTransform, the CubeMovementSystem should act on it
Okay. And I checked, CubeInput and LocalTransform are also in Cube of ClientWorld
Make sure its also the same in the Server World
It is (screenshots are in ServerWorld)
So yeah, i don't really understand. It is not a project from older version updated to 6, soooo
see if the NetCube sample from git will work in a fresh project
https://github.com/Unity-Technologies/EntityComponentSystemSamples/tree/master/NetcodeSamples
I will try by cloning it then putting the classes on a fresh one
It works on the cloned repo (Some delays for the client with many large serverTick error).
Copying the files to a new project doesn't seem to work. No errors, but I don't see any cube spawning (ingame nor in entity hierarchy)
Second try, still not succeeding upon transfering files to a new project
Ok it works !
It was a silly error from me alone. Here's the thing:
- By clicking on
CubeSpawnerAuthoringcomponent on theSpawnerGameObject, it showed me the location of the deprecatedCSAfrom Unity, but not the one I made from the tutorial - I tried to force add my
CubeSpawnerAuthoringbut i got a message that meant "must be a MonoBehavior" or something like that. - After a quick search, it appears it is because my name file was different from the class and yes, I named my file
CubeSpawnINGAuthoring. - After a quick rename, the movement works perfectly.