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

Issue

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://SomeClass.gd")
...
var instance = some_class.new(...args)
  1. Use class_name
# in SomeClass.gd
class_name some_class extends Object

# in place where class instantiated
var instance = some_class.new(...args)

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?



Solution

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?