#Transform reset after inserting pbr bundle

21 messages · Page 1 of 1 (latest)

static wedge
#

I have an entity that already has a transform, and want to give it a mesh afterwards. in the code below I am trying to preserve the transform in two ways but its not working:

fn init_player_system(
    mut cmds: Commands,
    q: Query<(Entity, &Transform), Added<Player>>,
    mut meshes: ResMut<Assets<Mesh>>,
    mut materials: ResMut<Assets<StandardMaterial>>,
) {
    for (entity, transform) in &q {
        cmds.entity(entity).insert(PbrBundle {
            mesh: meshes.add(Mesh::from(shape::Cube::default())),
            material: materials.add(StandardMaterial {
                base_color: Color::GREEN,
                ..default()
            }),
            transform: *transform,
            ..default()
        }).insert(*transform);
    }
}
fierce nymph
#

@static wedge
I feel like this should work, with the code above does it also resets the Transform, or does it not insert the PbrBundle at all (in which case maybe it's a problem of flushing the Transform before)?

Alternatively, you could just add the components of PbrBundle individually, there are not a lot of them, just Handle<Mesh>, Handle<StandardMaterial>, and potentially VisibilityBundleif your entity doesn't already have it.

static wedge
#

is that the issue?

fierce nymph
#

I need more information:

  • with the code that you showed first, what is the outcome: does it reset the Transform, or does it not insert the PbrBundle at all?
  • in which schedules are you adding the TransformBundle, and the PbrBundle?
static wedge
#

the code I showed is resetting the transform, pbr bundle does get inserted. the transformbundle gets spawned in update when a player joins, and then should get replicated to clients (bevy replicon) and then on the client for every added Player, a pbr bundle is spawned in update

fierce nymph
#

Are you sure your setup uses the correct transform for the client? Maybe it's not inserting the PbrBundle that resets it (I think your code above should work) but it's before that?

static wedge
#

yeah it seems like its happening before inserting the pbr, because I just removed the system and it still spawns at 0 0 0, instead of the 500 y I set it to. not sure how that is possible because these are the only things interacting with the entity

fierce nymph
#

I'm not familiar with bevy_replicon so I can't really help with that part, sorry ^^'

static wedge
#

the transform is maybe getting reset by the collider or somethign

fierce nymph
#

I thought it's bevy_replicon that spawns the object on the client side?

static wedge
#

yes, but on the server the transform is already wrong

fierce nymph
#

ah

static wedge
#

as soon as it spawns

fierce nymph
static wedge
#

wait, it seems like bevy_xpbd is using its own position instead of the transform

#

maybe that is whats happening

fierce nymph
#

Ah yeah definitely

#

It might change in the future but for now it's the Position you need to set

#

I should have thought about that I did the same mistake :')