0 votes

I believe I'm misunderstanding how an instanced-scene is utilized (here's a quick little example project).

EDIT: OK, so the example works. Why wont my main project behave the same way?
SOLVED: Within my project, Character.gd I had _init( some_arg ): set and... I don't know. Removing the argument fixed the problem. I also re-added the class name class_name Character without any issue. Hopefully this may save 2 days of troubleshooting for someone else. I'll update my example to help illustrate the issue. On the up-side, I've read a lot more about the difference between .new() and .instance() ~ very helpful for in-code instantiation.

All I want to do is access char_name from RootScene.

What's going on here?
If I create a scene starting with KinematicBody and attach a script like so...

class_name Character extends KinematicBody 
char_name = "Npc Boi"

...then I create and save a scene as follows...

 |- CollisionShape
 |- Sprite3D
 |- RayCast


If I hover over "Character" it says "Type: Character."
In the editor, I add an instance of this scene as a node into another scene...

|- WorldScene
     |- Character


In the editor, hovering over the scene~instance, it says Type: KinematicBody.

extends Node
var c : Character
func _ready():
    c = get_node("Character")


Godot says Trying to assign value of Type: KinematicBody even though the script of its root ("Character") extends it. If I save it as type KinematicBody then var c will not exist.

How can I save a reference to my character from RootScene._ready() without adding a bloatware-container root?

We seem to lose the script~reference when i instance the Character scene. Weirder: In the editor, when I switch from "Local" to "Remote" than hovering over both instances (the tree and the instanced scene) will say "Type: KinematicBody". If I change RootScene.gd var c : KinematicBody then, as expected, char_name is not accessable.

Godot version latest
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.