Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in adding child in custom schematics #64

Closed
hafiidz opened this issue Oct 18, 2023 · 1 comment
Closed

Error in adding child in custom schematics #64

hafiidz opened this issue Oct 18, 2023 · 1 comment

Comments

@hafiidz
Copy link
Contributor

hafiidz commented Oct 18, 2023

I am using custom schematics to add player sprite and some text to the window.
Not sure exactly what is the root problem, but after a few changes including migrating from bevy_proto 0.11 release to latest github version, I couldn't get the add child text working. The screenshot demonstrating the child text appearance in old build vs new.

Old build:
Screenshot 2023-10-18 091719

New build:
image

impl Schematic for PlayerSpriteSheet {
    // Applying `EnemyInput` type
    type Input = PlayerSpriteSheet;

    fn apply(input: &Self::Input, _id: SchematicId, context: &mut SchematicContext) {

       //skipped some section to load atlas & transform

        context.entity_mut().unwrap().insert((
            SpriteSheetBundle {
                texture_atlas: texture_atlas_handle,
                sprite: TextureAtlasSprite::new(input.sprite.animation.first),
                transform,
                ..default()
            },
            input.sprite.animation,
            AnimationTimer(Timer::from_seconds(
                input.sprite.animation.duration,
                TimerMode::Repeating,
            )),
            PlayerSprite,
        ));

        // Insert the Defend Text within the 2d world (i.e. not using node UI)

        let text = "Defend: 1".to_string();

        let defend_text = context
            .world_mut()
            .spawn((
                Text2dBundle {
                    text: Text::from_section(
                        // Accepts a String or any type that converts into a String, such as &str.
                        text,
                        TextStyle {
                            font_size: 200.0,
                            color: Color::RED,
                            ..default()
                        },
                    ),
                    visibility: Visibility::Visible,
                    ..Default::default()
                },
                PlayerDefendUIText,
            ))
            .id();

        // add health bar & text child entity to Enemy
        context.entity_mut().unwrap().add_child(defend_text);
    }

    // skipped 
    // fn remove()
    // fn preload_dependencies()

I have a debug system/function to print all entity to console, and when I do that, the child entity exist. Not sure what else can be done to diagnose this new behavior further.

[src\state\mod.rs:255] entity = 26v0
        Component: bevy_transform::components::transform::Transform
        Component: bevy_transform::components::global_transform::GlobalTransform
        Component: bevy_hierarchy::components::parent::Parent
        Component: bevy_render::view::visibility::ComputedVisibility
        Component: bevy_text::text::Text
        Component: deck_proto::app::schematic::player::PlayerDefendUIText
        Component: bevy_render::view::visibility::Visibility
        Component: bevy_text::text2d::Text2dBounds
        Component: bevy_text::pipeline::TextLayoutInfo
        Component: bevy_sprite::sprite::Anchor
@hafiidz
Copy link
Contributor Author

hafiidz commented Oct 18, 2023

Just did a search on main bevy github, this could be a bevy bug instead bevyengine/bevy#9676. Closing this for now.

@hafiidz hafiidz closed this as completed Oct 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant