Closed sanchopanca closed 4 years ago
I'm not 100% sure if this is a bug or the documentation being incorrect. Does it work if you try to create a Reference or a Resource instead? (You're more likely to use a Reference than an Object in a real-world project due to automatic memory management.)
I would argue it is a bug, since it is possible to create a plain Object through other means (thus it is not impossible to have one by-design) and since it is not ambiguous what the user wants when doing Object.new()
.
For an example of creating a plain object, consider:
extends Node
class X extends Object:
pass
func _ready():
var obj1 = ClassDB.instance("Object")
print(obj1) # [Object:XXXX]
var obj2 = X.new()
obj2.set_script(null)
print(obj2) # [Object:XXXX+1]
Does it work if you try to create a Reference or a Resource instead?
Yes it works, as well as any other subclass of Object
it seems.
I say it's a bug even if the use cases for instantiating a pure Object
reaches 0, but I'm sure there are. In C++ it's certainly possible to instantiate an Object
:
In theory you can use this as some kind of a placeholder. Creating pure objects may also be useful for mock testing. Or use objects as struct data with set_meta
and get_meta
. Dictionaries are better suited for this, but you may lack more advanced functionality by attaching a script with set_script
to extend an object at run-time.
Forbidding the instantiation of other "abstract" classes like Reference
or Resource
from script altogether may also end up more work than allowing instantiation of Object
alone, so lets not strip advanced functionality for the sake of making Godot "beginner friendly", I'd still like to use some advanced features while I still can, even if they're not completely obvious or not documented.
In any case, we're talking about completeness. The fact that this issue was reported tells there's something which got a user feel empty inside. 😄
Godot version: 3.2.2.stable.official
OS/device including version: Windows 10, PC
Issue description: An attempt to create an instance of
Object
by callingObject.new()
ends with the following error:Parse Error: Static constant 'new' not present in built-in type Object
This contradicts the documentation of Object that mentions the following:Steps to reproduce: Put the following in to
object-new.gd
:Then run:
Minimal reproduction project: object-new-bug-report.zip