@@ -1511,8 +1511,15 @@ void LightmapGI::_notification(int p_what) {
15111511void LightmapGI::_assign_lightmaps () {
15121512 ERR_FAIL_COND (light_data.is_null ());
15131513
1514+ Vector<String> missing_node_paths;
1515+
15141516 for (int i = 0 ; i < light_data->get_user_count (); i++) {
1515- Node *node = get_node (light_data->get_user_path (i));
1517+ NodePath user_path = light_data->get_user_path (i);
1518+ Node *node = get_node_or_null (user_path);
1519+ if (!node) {
1520+ missing_node_paths.push_back (user_path);
1521+ continue ;
1522+ }
15161523 int instance_idx = light_data->get_user_sub_instance (i);
15171524 if (instance_idx >= 0 ) {
15181525 RID instance_id = node->call (" get_bake_mesh_instance" , instance_idx);
@@ -1525,12 +1532,25 @@ void LightmapGI::_assign_lightmaps() {
15251532 RS::get_singleton ()->instance_geometry_set_lightmap (vi->get_instance (), get_instance (), light_data->get_user_lightmap_uv_scale (i), light_data->get_user_lightmap_slice_index (i));
15261533 }
15271534 }
1535+
1536+ if (!missing_node_paths.is_empty ()) {
1537+ String missing_paths_text;
1538+ if (missing_node_paths.size () <= 3 ) {
1539+ missing_paths_text = String (" , " ).join (missing_node_paths);
1540+ } else {
1541+ missing_paths_text = vformat (" %s and %d more" , String (" , " ).join (missing_node_paths.slice (0 , 3 )), missing_node_paths.size () - 3 );
1542+ }
1543+ WARN_PRINT (vformat (" %s couldn't find previously baked nodes and needs a rebake (missing nodes: %s)." , get_name (), missing_paths_text));
1544+ }
15281545}
15291546
15301547void LightmapGI::_clear_lightmaps () {
15311548 ERR_FAIL_COND (light_data.is_null ());
15321549 for (int i = 0 ; i < light_data->get_user_count (); i++) {
1533- Node *node = get_node (light_data->get_user_path (i));
1550+ Node *node = get_node_or_null (light_data->get_user_path (i));
1551+ if (!node) {
1552+ continue ;
1553+ }
15341554 int instance_idx = light_data->get_user_sub_instance (i);
15351555 if (instance_idx >= 0 ) {
15361556 RID instance_id = node->call (" get_bake_mesh_instance" , instance_idx);
0 commit comments