# Cannot call a function from another class

**URL:** <https://forum.godotengine.org/t/cannot-call-a-function-from-another-class/6793>\
**Category:** Archive\
**Created:** [April 15, 2022, 3:50pm UTC](https://forum.godotengine.org/t/cannot-call-a-function-from-another-class/6793 "2022-04-15T15:50:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://forum.godotengine.org/uploads/default/original/2X/4/4b0a7fa8a6334634b94a13d421f0d99e6f04e21f.svg) [@system](https://forum.godotengine.org/u/system)\
**Post date:** [April 15, 2022, 3:50pm UTC](https://forum.godotengine.org/t/cannot-call-a-function-from-another-class/6793/1 "2022-04-15T15:50:03Z")

</div>

| | | |
| --- | --- | --- |
| ℹ | **Attention** | Topic was automatically imported from the old Question2Answer platform. |
| 👤 | **Asked&nbsp;By** | huny |

I can call the class, but how do I call the function?

This is the code for the class I want to call.

```auto
#MyClass.gd

class_name MyClass

func FuncA():
	pass

```

I want to call FuncA in this class.

```auto
#Player.gd

extends KinematicBody

func _ready():
	
	var myClass = MyClass.new() #Non Error.
	
	myClass.FuncA()	#This is Error.

```

Sorry for the elementary question. Am I missing something?

---

<div class="post-metadata">

**Author:** ![system](https://forum.godotengine.org/uploads/default/original/2X/4/4b0a7fa8a6334634b94a13d421f0d99e6f04e21f.svg) [@system](https://forum.godotengine.org/u/system)\
**Post date:** [April 15, 2022, 4:06pm UTC](https://forum.godotengine.org/t/cannot-call-a-function-from-another-class/6793/2 "2022-04-15T16:06:17Z")

</div>

| | | |
| --- | --- | --- |
| 👤 | **Reply From:** | jgodfrey |

* * *

UPDATE - The below answer was based on a misunderstanding of the original question. See the conversation in comments below for more helpful information. (I wish the forum supported strike-through text for better visibility here…)

* * *

You’re probably running into the same misunderstanding as described (and resolved) here:

[https://forum.godotengine.org/16097/how-do-you-call-class-methods-from-an-external-gdscript-file](https://forum.godotengine.org/16097/how-do-you-call-class-methods-from-an-external-gdscript-file)

I have done the same but it does not work.  
its Q&A seems to have calling a script, but I seem to have calling a reference on my end.  
Also, what is the difference between “class” and “class\_name”?

huny | 2022-04-15 16:34

Hmmm… Sorry, looks like I misread your post. What you show should work as expected.

If I create a file named `MyClass.gd` with this content:

```auto
class_name MyClass

func FuncA():
	print("Called FuncA")

```

… and then, from another script, do this (for example):

```auto
func _ready():
	var myClass = MyClass.new()
	myClass.FuncA()

```

The function is called and I see _called FuncA_ printed in the console. Is what you’re doing somehow different?

jgodfrey | 2022-04-15 16:42

To your earlier question `class_name` just registers a name (and, optionally, an icon) for the class represented by the current script. The`class` keyword creates an _inner_ class.

Search for those terms here for more info: [https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript\_basics.html?highlight=class\_name](https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html?highlight=class_name)

jgodfrey | 2022-04-15 16:49

I was trying different things and it worked!  
As a matter of fact, I had named the class StateMachine (for clarity for questions).  
It did not work with the name StateMachine, but it worked fine with the names MyStateMachine and StateMachine\_.

I didn’t understand what was going on, but it worked anyway. Thank you for your patience.

huny | 2022-04-15 17:05
