Where is the mistake?
Asked Answered
G

8

0

'Area2D' does not contain a 'Start' definition, and could not find an accessible 'Start' connection method that takes the type 'Area2D' as its first argument (possibility, missing using directive or assembly reference).

Gelderland answered 20/3, 2023 at 22:43 Comment(0)
P
0

I'm guessing your player object has a class like Player (since that's how you add functions to existing node types).
Assuming that's the case...
when you do GetNode<Area2D>("Player") you get an Area2D reference. The object is really a Player, but the reference only knows about Area2D and therefore can't see the Start function.

Try changing the line to:
var player = GetNode<Player>("Player");
(or whatever your class is called)

Pournaras answered 21/3, 2023 at 7:13 Comment(0)
A
0

I bet it’s Start with a lowercase s. Also I like how you used the free tag. Haha, free help.

Apprehensive answered 20/3, 2023 at 23:4 Comment(0)
G
0

Apprehensive Unfortunately, Start is written correctly (Maybe this will help to understand what the problem is?)

Gelderland answered 20/3, 2023 at 23:21 Comment(0)
G
0

Up

Gelderland answered 21/3, 2023 at 5:45 Comment(0)
A
0

You are calling start() on two separate nodes but I only see code implemented for one of those

Apprehensive answered 21/3, 2023 at 6:9 Comment(0)
P
0

I'm guessing your player object has a class like Player (since that's how you add functions to existing node types).
Assuming that's the case...
when you do GetNode<Area2D>("Player") you get an Area2D reference. The object is really a Player, but the reference only knows about Area2D and therefore can't see the Start function.

Try changing the line to:
var player = GetNode<Player>("Player");
(or whatever your class is called)

Pournaras answered 21/3, 2023 at 7:13 Comment(0)
G
0

Area2D does not have any function called Start. Maybe your custom class, which inherits from Area2D does. But in that case, you need a reference to your class, not Area2D. In GDScript it's implicit, or you can define a name with class_name. In C# it's probably defined when you inherit the class, but I don't know off hand cause I only use GDScript.

Goblet answered 21/3, 2023 at 8:35 Comment(0)
P
0

Goblet In C# it's probably defined when you inherit the class,

Yep. Here's the code I made as a test:
Parent object:

using Godot;
using System;

public class Base : Node2D
{
	public override void _Ready()
	{
		var player = GetNode<Player>("Player");
		player.Start();
	}
}

Player object:

using Godot;
using System;

public class Player : Area2D
{
	public override void _Ready()
	{
	}

	public void Start()
	{
	}
}
Pournaras answered 21/3, 2023 at 9:1 Comment(0)
G
0

Thanks everyone! Helped a lot, changed <Area2D> to <playercontroller> the name of the class that was written in the code

Gelderland answered 21/3, 2023 at 10:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.