#NFE Physics Spawning

1 messages · Page 1 of 1 (latest)

crude gyro
#

post your spawning system here and we can take a look to see what might be happening

untold helm
#

The spawning system:


using UnityEngine;
using Unity.Entities;
using Unity.Burst;
using Unity.Collections;
using Unity.Mathematics;
using Unity.Physics;
using Unity.Transforms;
using Random = Unity.Mathematics.Random;

public struct Config : IComponentData
{
    public Entity CubePrefab;
    public int CubeCount;
}

[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
public partial struct CubeSpawningSystem : ISystem
{
    [BurstCompile]
    public void OnCreate(ref SystemState state)
    {
        Debug.Log("on_create");
        state.RequireForUpdate<Config>();
        // state.RequireForUpdate<PhysicsStep>();
    }

    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        var config = SystemAPI.GetSingleton<Config>();

        var rand = new Random(132131541);

        var ecb = new EntityCommandBuffer(Allocator.Temp);


        for (int i = 0; i < config.CubeCount; i++)
        {
            var entity = ecb.Instantiate(config.CubePrefab);
            ecb.SetComponent(entity, new LocalTransform
            {
                Position = new float3(i - 500, 100, 0),
                Rotation = quaternion.EulerXYZ(new float3(rand.NextFloat(0, 360), rand.NextFloat(0, 360),
                    rand.NextFloat(0, 360))),
                Scale = 1
            });
        }
        
        ecb.Playback(state.EntityManager);

        // }



        state.Enabled = false;
    }
}```
#

The entity prefab

#

The spawned entities have a "Static" tag, and no PhysicsVelocity components are added

crude gyro
#

is the cube authoring component setting the TransformFlag to Dynamic?

untold helm
#
{

    public class Baker : Baker<CubeAuthoring>
    {
        public override void Bake(CubeAuthoring authoring)
        {
            var entity = GetEntity(TransformUsageFlags.Dynamic);
            AddComponent(entity,new  PhysicsVelocity
            {
                
            });
        }
    }
    
}```
#

Following your suggestion I added this CubeAuthoring. However, it's still marked Static, and PhysicsVelocity does not get updated by gravity.

#

However, if I manually set the PhysicsVelocity values in the editor, they start to move the transforrm

crude gyro
untold helm
#

I already have a NetCodePhysicsConfig set to "AlwaysRun" for the PhysicsGroup run mode. So there shouldn't need to be a predicted ghost in the scene.

crude gyro
untold helm
#

I manually added a PhysicsMass and a PhysicsVelocity component to the cubes, and they seem to get updated by physics now.

#

But they're still not synchronized with the client, and it looks like I needed to set a "NetworkStreamInGame" component on a NetworkId on the server to start synchronizing, which I did, but still doesn't work. 🤷

#

Appreciate your help though

#

The docs say, "A ghost is spawned by instantiating it on the server, as all ghosts on the server are replicated to all clients automatically."

untold helm