Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Help : Error with _init #364

Closed
Grazulex opened this issue Jan 2, 2025 · 2 comments
Closed

Help : Error with _init #364

Grazulex opened this issue Jan 2, 2025 · 2 comments
Labels
🐛 bug Something isn't working

Comments

@Grazulex
Copy link

Grazulex commented Jan 2, 2025

Godot version: 4.3.stable

Describe the bug
Have a error when use _init function in action

To Reproduce

extends ActionLeaf
class_name Walking_Action

var target: NodePath

func _init(target: NodePath):
	self.target = target

func tick(actor: Node, blackboard: Blackboard) -> int:
	var target_node = blackboard.get_node(self.target)
	if target_node == null
:
		return FAILURE

Hello, I starting to use your addon and i'm just testing some examples and when I used a _init function in a action I have this error :

E 0:00:00:0339   _create_instance: Error constructing a GDScriptInstance: 'Node(walking_action.gd)::_init': Method expected 1 arguments, but called with 0
  <C++ Error>    Method/function failed. Returning: nullptr
  <C++ Source>   modules/gdscript/gdscript.cpp:196 @ _create_instance()

and Godot open the sequence.gd file on this line :

		if c != running_child:
			c.before_run(actor, blackboard)

Sure that I have forget something but I don't know what :-(

@Grazulex Grazulex added the 🐛 bug Something isn't working label Jan 2, 2025
@apollothecodemeleon
Copy link

it looks like in the file modules/gdscript/gdscript.cpp on line 196, the script calls the function _create_instance without any arguments, which you can see because the error message says that the line says _create_instance() without any args in the parentheses. I am not sure how to fix that, but i can, and just explained what is wrong.

@bitbrain
Copy link
Owner

In Godot, you cannot have an _init() function with more than 0 args when you wish nodes to be instantiated via scene tree. When adding nodes to your scene, Godot will call _init() for you but always with no arguments. By overriding the _init you basically prevent Godot from doing that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants