Skip to content

Support arrays of BsnValue as a BsnFnArg - #25942

Open
zincdev0 wants to merge 2 commits into
bevyengine:mainfrom
zincdev0:bsn-value-array
Open

zincdev0 wants to merge 2 commits into
bevyengine:mainfrom
zincdev0:bsn-value-array

Conversation

@zincdev0

Copy link
Copy Markdown
Contributor

Objective

Currently, entity references in bsn are limited to positions where BsnValues are parsed.

This PR addresses that limitation for arrays in function arguments. The entity reference limitations of bsn should probably not be addressed individually, but this particular case is kind of a blocker for allowing bevy_enhanced_input to use bsn.

Solution

A new variant has been added to BsnFnArg for arrays, which allows any amount of BsnValues in a list.

Testing

A regression test (arrays_in_bsn) has been added to crates/bevy_scene/src/lib.rs.

@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Scenes Composing and serializing ECS objects S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Sep 27, 2026
@alice-i-cecile alice-i-cecile added D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes D-Macros Code that generates Rust code labels Sep 27, 2026
@Shatur Shatur added this to the 0.20 milestone Oct 6, 2026
#[test]
fn arrays_in_bsn() {
#[derive(Component)]
struct Foo(Vec<Entity>);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have another test case where the internals are a true array of [Entity; 3]?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then use direct literal construction for it.

bracketed!(content in forked);
let parse_punctuated_bsn_values = || -> Result<Vec<BsnValue>> {
let mut values = Vec::new();
parse_punctuated_vec_autocomplete_friendly!(values, content, BsnValue, Comma);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've swapped out the default "punctuated" parsing logic for our "autocomplete friendly" parsing logic

@cart cart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm on board for the general direction here. I'm thinking ultimately we'll want to consider making this a BsnValue variant so we can support it in arbitrary value positions, but that does mean making our parsing logic more expensive and complicated. This is a good temporary solution.

@alice-i-cecile alice-i-cecile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks basically good, but there are a few regressions introduced. See zincdev0#1 for some failing tests.

The core problem here is that BsnFnArg::parse commits to "aha! an array!" too eagerly :)

#[test]
fn arrays_in_bsn() {
#[derive(Component)]
struct Foo(Vec<Entity>);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then use direct literal construction for it.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Scenes Composing and serializing ECS objects C-Bug An unexpected or incorrect behavior D-Macros Code that generates Rust code D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants