Proper way to instanciate class in godot (preload vs class_name)


This Content is from Stack Overflow. Question asked by iwek

As far as I am aware there are two main ways to instantiate class in gdscript 2.0.

  1. Preload/load class with script and create instance:
var some_class = preload("res://")
var instance =
  1. Use class_name
# in
class_name some_class extends Object

# in place where class instantiated
var instance =

Which way to create new instance of class is preferred? What are differences between two methods? Is there any reason to avoid just using export_class everywhere?


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?