@@ -7,12 +7,12 @@ use bevy::{
77 world:: { Command , EntityRef , World } ,
88 } ,
99 prelude:: {
10- AppTypeRegistry , BuildWorldChildren , Children , DespawnChildrenRecursive , DespawnRecursive ,
10+ AppTypeRegistry , BuildChildren , Children , DespawnChildrenRecursive , DespawnRecursive ,
1111 Entity , Parent , ReflectComponent , ReflectDefault , ReflectResource ,
1212 } ,
1313 reflect:: {
14- DynamicArray , DynamicEnum , DynamicList , DynamicMap , DynamicStruct , DynamicTuple ,
15- DynamicTupleStruct , TypeRegistration ,
14+ DynamicArray , DynamicEnum , DynamicList , DynamicMap , DynamicSet , DynamicStruct ,
15+ DynamicTuple , DynamicTupleStruct , TypeRegistration ,
1616 } ,
1717} ;
1818use bevy_mod_scripting_core:: { prelude:: ScriptError , world:: WorldPointer } ;
@@ -169,35 +169,35 @@ impl ScriptWorld {
169169
170170 pub fn push_child ( & self , parent : Entity , child : Entity ) {
171171 let mut w = self . write ( ) ;
172- if let Some ( mut entity) = w. get_entity_mut ( parent) {
173- entity. push_children ( & [ child] ) ;
172+ if let Ok ( mut entity) = w. get_entity_mut ( parent) {
173+ entity. add_children ( & [ child] ) ;
174174 }
175175 }
176176
177177 pub fn remove_children ( & self , parent : Entity , children : & [ Entity ] ) {
178178 let mut w = self . write ( ) ;
179179
180- if let Some ( mut entity) = w. get_entity_mut ( parent) {
180+ if let Ok ( mut entity) = w. get_entity_mut ( parent) {
181181 entity. remove_children ( children) ;
182182 }
183183 }
184184
185185 pub fn insert_children ( & self , parent : Entity , index : usize , children : & [ Entity ] ) {
186186 let mut w = self . write ( ) ;
187187
188- if let Some ( mut entity) = w. get_entity_mut ( parent) {
188+ if let Ok ( mut entity) = w. get_entity_mut ( parent) {
189189 entity. insert_children ( index, children) ;
190190 }
191191 }
192192
193193 pub fn despawn_children_recursive ( & self , entity : Entity ) {
194194 let mut w = self . write ( ) ;
195- DespawnChildrenRecursive { entity } . apply ( & mut w) ;
195+ DespawnChildrenRecursive { entity, warn : true } . apply ( & mut w) ;
196196 }
197197
198198 pub fn despawn_recursive ( & self , entity : Entity ) {
199199 let mut w = self . write ( ) ;
200- DespawnRecursive { entity } . apply ( & mut w) ;
200+ DespawnRecursive { entity, warn : true } . apply ( & mut w) ;
201201 }
202202
203203 pub fn get_type_by_name ( & self , type_name : & str ) -> Option < ScriptTypeRegistration > {
@@ -225,7 +225,7 @@ impl ScriptWorld {
225225
226226 let mut entity_ref = w
227227 . get_entity_mut ( entity)
228- . ok_or_else ( | | ScriptError :: Other ( format ! ( "Entity is not valid {:#?}" , entity) ) ) ?;
228+ . map_err ( |e | ScriptError :: Other ( format ! ( "Entity is not valid {:#?}. {e }" , entity) ) ) ?;
229229
230230 let component_data = comp_type. data :: < ReflectComponent > ( ) . ok_or_else ( || {
231231 ScriptError :: Other ( format ! ( "Not a component {}" , comp_type. short_name( ) ) )
@@ -243,13 +243,14 @@ impl ScriptWorld {
243243 bevy:: reflect:: TypeInfo :: List ( _) => component_data. insert ( & mut entity_ref, & DynamicList :: default ( ) , & registry_lock) ,
244244 bevy:: reflect:: TypeInfo :: Array ( _) => component_data. insert ( & mut entity_ref, & DynamicArray :: new ( Box :: new ( [ ] ) ) , & registry_lock) ,
245245 bevy:: reflect:: TypeInfo :: Map ( _) => component_data. insert ( & mut entity_ref, & DynamicMap :: default ( ) , & registry_lock) ,
246- bevy:: reflect:: TypeInfo :: Value ( _) => component_data. insert ( & mut entity_ref,
246+ bevy:: reflect:: TypeInfo :: Set ( set_info) => component_data. insert ( & mut entity_ref, & DynamicSet :: default ( ) , & registry_lock) ,
247+ bevy:: reflect:: TypeInfo :: Opaque ( _) => component_data. insert ( & mut entity_ref,
247248 comp_type. data :: < ReflectDefault > ( ) . ok_or_else ( ||
248249 ScriptError :: Other ( format ! ( "Component {} is a value or dynamic type with no `ReflectDefault` type_data, cannot instantiate sensible value" , comp_type. short_name( ) ) ) ) ?
249250 . default ( )
250- . as_ref ( ) ,
251+ . as_partial_reflect ( ) ,
251252 & registry_lock) ,
252- bevy:: reflect:: TypeInfo :: Enum ( _) => component_data. insert ( & mut entity_ref, & DynamicEnum :: default ( ) , & registry_lock)
253+ bevy:: reflect:: TypeInfo :: Enum ( _) => component_data. insert ( & mut entity_ref, & DynamicEnum :: default ( ) , & registry_lock) ,
253254 } ;
254255 // if we do not drop the lock here, line below will complain registry is still borrowed at drop
255256 drop ( registry_lock) ;
@@ -273,7 +274,7 @@ impl ScriptWorld {
273274
274275 let entity_ref = w
275276 . get_entity ( entity)
276- . ok_or_else ( | | ScriptError :: Other ( format ! ( "Entity is not valid {:#?}" , entity) ) ) ?;
277+ . map_err ( |e | ScriptError :: Other ( format ! ( "Entity is not valid {:#?}. {e }" , entity) ) ) ?;
277278
278279 let component_data = comp_type. data :: < ReflectComponent > ( ) . ok_or_else ( || {
279280 ScriptError :: Other ( format ! ( "Not a component {}" , comp_type. short_name( ) ) )
@@ -296,7 +297,7 @@ impl ScriptWorld {
296297
297298 let entity_ref = w
298299 . get_entity ( entity)
299- . ok_or_else ( | | ScriptError :: Other ( format ! ( "Entity is not valid {:#?}" , entity) ) ) ?;
300+ . map_err ( |e | ScriptError :: Other ( format ! ( "Entity is not valid {:#?}. {e }" , entity) ) ) ?;
300301
301302 Ok ( component_data. reflect ( entity_ref) . is_some ( ) )
302303 }
@@ -310,7 +311,7 @@ impl ScriptWorld {
310311
311312 let mut entity_ref = w
312313 . get_entity_mut ( entity)
313- . ok_or_else ( | | ScriptError :: Other ( format ! ( "Entity is not valid {:#?}" , entity) ) ) ?;
314+ . map_err ( |e | ScriptError :: Other ( format ! ( "Entity is not valid {:#?}. {e }" , entity) ) ) ?;
314315
315316 let component_data = comp_type. data :: < ReflectComponent > ( ) . ok_or_else ( || {
316317 ScriptError :: Other ( format ! ( "Not a component {}" , comp_type. short_name( ) ) )
0 commit comments