#Entity creation issues

1 messages · Page 1 of 1 (latest)

slim stag
#

public void OnUpdate(ref SystemState state)
{
var ecb = new EntityCommandBuffer(Unity.Collections.Allocator.Temp);
foreach (var (rpcRequest, swapClassRPC, entity) in SystemAPI.Query<RefRO<ReceiveRpcCommandRequest>, RefRO<SwapClassRequest>>().WithEntityAccess())
{
Entity connection = rpcRequest.ValueRO.SourceConnection;
Entity playerEntity = state.EntityManager.GetComponentData<CommandTarget>(connection).targetEntity;

        if (playerEntity == Entity.Null) { UnityEngine.Debug.Log("AAAAA"); return; }
        FirstPersonPlayer firstPersonPlayer = SystemAPI.GetComponent<FirstPersonPlayer>(playerEntity);
        ecb.DestroyEntity(firstPersonPlayer.ControlledCharacter);
        var controlledCharacter = ecb.Instantiate(SystemAPI.GetSingleton<CharacterClassDatabase>().Database.Value.entityLibrary[swapClassRPC.ValueRO.classID]);
        firstPersonPlayer.ControlledCharacter = controlledCharacter;
        ecb.DestroyEntity(entity);

    }
    ecb.Playback(state.EntityManager);
}

//////

This gives me a million different errors.

(For context, CharacterClassDatabase is a BlobAsset and I'm using the sample first person charactercontroller)

prisma stone
slim stag
#

It's the creation of an entity in the ClassSwappingSystemServer

#

I did go through the getting-started sample. Are there any other things I can use to learn this better, because all of this is incredibly abstract and hurting my brain?

#

I want to make a class-based shooter so what I'm trying to do is swap the current player-controlled entity to a different prefab that has an orange tint.

Is commandTarget the right way to get the player prefab from an rpc?

slim stag
#

should I try making a DOTs singleplayer game before jumping over to networking?

#

sry for spam I'm just losing my mind

slim stag
#

cool

#

thx!

prisma stone
#

You will need to learn DOTS before jumping into netcode
But go through all the samples