onready var _boardView_scene = load("res://UrBoardView.tscn")
gets the scene reference.
Then I try to instance the scene like this _urBoardViewInstance = _boardView_scene.instance()
. The UrBoardView scene has a script of type BoardView like this to its topmost node(meaning the scene is of type BoardView)-
extends Node
class_name BoardView
The _urBoardViewInstance
get instanced as a Node here. Casting it to BoardView is not working(giving null) here - var boardViewCast = _urBoardViewInstance as BoardView
I need to call a custom init method from BoardView script before sending it to add_child(_urBoardViewInstance)
.
Basically, I want to instance the scene not as a node but as the type of script that it has attached.(or just call like this
_urBoardViewInstance = _boardView_scene.instance().new(board)
which apparently is not possible in Godot right now.) And that casting is not working. This is the how I am casting -
var boardViewCast: BoardView
_urBoardViewInstance = _boardView_scene.instance()
boardViewCast = _urBoardViewInstance as BoardView
boardViewCast.init(gameplay.Board)
the boardViewCast
is null after this. It basically does not cast at all.