classname StateMachine extends Node @export var initalstate = NodePath() @onready var CS…
- User
class_name StateMachine extends Node @export var inital_state = NodePath() @onready var CS = get_node(inital_state)
Called when the node enters the scene tree for the first time.
func _ready(): for child in get_children(): print(child) child.state_machine=self child.character=get_parent() child.animation=get_parent().get_node("VisualNode/AnimationPlayer")
Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): pass
من میخوام این ارور از کدم ورداشته شه Invalid set index 'state_machine' (on base: 'Node3D (Playeridle.gd)') with value of type 'Node3D (StateMachine)'.
- Assistant
به نظر میرسد که اروری که دریافت میکنید به دلیل این است که شیء
childکه ازget_children()به دست میآید، دارای پراپرتیstate_machineنمیباشد. برای حل این مشکل، میتوانید کد خود را به گونهای تغییر دهید که ابتدا بررسی کند آیا child دارای پراپرتیstate_machineمیباشد یا خیر.در اینجا کد ویرایششده را مشاهده میکنید:
extends Node @export var inital_state = NodePath() @onready var CS = get_node(inital_state) # Called when the node enters the scene tree for the first time. func _ready(): for child in get_children(): print(child) # بررسی کنید که child دارای پراپرتی state_machine میباشد if hasattr(child, "state_machine"): child.state_machine = self if hasattr(child, "character"): child.character = get_parent() if hasattr(child, "animation"): child.animation = get_parent().get_node("VisualNode/AnimationPlayer") # Called every frame. 'delta' is the elapsed time since the previous frame. func _process(delta): pass