From 5670e3380d53e84e126955c9f106183dbfaff97b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=A8=E8=90=BD=E5=9F=BA=E5=9B=B4=E8=99=BE?= <3161880837@qq.com> Date: Sun, 18 Jan 2026 14:51:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(BulletBase):=20=E6=B7=BB=E5=8A=A0=E7=88=B6?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E6=9C=89=E6=95=88=E6=80=A7=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E9=98=B2=E6=AD=A2=E5=B4=A9=E6=BA=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在子弹分裂和折射时检查父节点是否有效,避免无效引用导致的崩溃 --- components/Characters/Rooster.tscn | 5 ++--- scripts/Statemachine/BulletBase.gd | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/components/Characters/Rooster.tscn b/components/Characters/Rooster.tscn index 80dd2ed..fc4d8e4 100644 --- a/components/Characters/Rooster.tscn +++ b/components/Characters/Rooster.tscn @@ -2,7 +2,7 @@ [ext_resource type="PackedScene" uid="uid://cvogxi7mktumf" path="res://components/Abstracts/EntityBase.tscn" id="1_e5pl8"] [ext_resource type="Script" uid="uid://cthtupc6dtbav" path="res://scripts/Contents/Characters/Rooster.gd" id="2_oqdqd"] -[ext_resource type="PackedScene" uid="uid://dlaks67h2osms" path="res://components/Weapons/ChainGun.tscn" id="3_s7kxe"] +[ext_resource type="PackedScene" uid="uid://c3crr8r7y3oho" path="res://components/Weapons/BlueCrystal.tscn" id="3_da2ca"] [ext_resource type="AudioStream" uid="uid://cdrevrq7n6yqa" path="res://resources/sounds/effect/Boing.mp3" id="4_66s6c"] [ext_resource type="AudioStream" uid="uid://benyec5bqni0b" path="res://resources/sounds/effect/Chomp.wav" id="4_k0yme"] [ext_resource type="AudioStream" uid="uid://dmxh3bpk8vyy5" path="res://resources/sounds/effect/Coin.mp3" id="5_xnbhq"] @@ -58,8 +58,7 @@ metadata/_edit_vertical_guides_ = [71.0] [node name="weaponStore" parent="." index="1"] process_mode = 4 -[node name="ChainGun" parent="weaponStore" index="0" instance=ExtResource("3_s7kxe")] -debugRebuild = false +[node name="BlueCrystal" parent="weaponStore" index="0" instance=ExtResource("3_da2ca")] [node name="sprint" parent="sounds" index="0"] stream = ExtResource("4_66s6c") diff --git a/scripts/Statemachine/BulletBase.gd b/scripts/Statemachine/BulletBase.gd index c9ba001..86e7127 100644 --- a/scripts/Statemachine/BulletBase.gd +++ b/scripts/Statemachine/BulletBase.gd @@ -152,7 +152,8 @@ func trySplit(): cloned.rotation += deg_to_rad(360.0 / total * i + 180) cloned.canDuplicateSelf = false cloned.launcher = launcher - cloned.parent = parent + if is_instance_valid(parent): + cloned.parent = parent get_parent().add_child.call_deferred(split(cloned, i, total, last)) func tryRefract(): if is_instance_valid(launcher) and canDuplicateSelf: @@ -173,7 +174,8 @@ func tryRefract(): cloned.look_at(entity.position) cloned.canDuplicateSelf = false cloned.launcher = launcher - cloned.parent = parent + if is_instance_valid(parent): + cloned.parent = parent get_parent().add_child.call_deferred(refract(cloned, entity, i, total, last)) # 抽象方法