Ok, so I’m trying to make a function to swap between cameras (using the Phantom Camera plugin) but for some reason, whenever I call the PhantomCamera node, it comes back as null.
Here’s the function:
extends Node3D
@export var Camera : PhantomCamera3D
func change_cam(Priority_Change : int):
Camera.priority = Priority_Change
And here’s it being used (it being controlled by a button is just for debug purposes, not an actual feature):
if Input.is_action_just_pressed("back_ability"):
Game.change_cam(8)
And finally, the error that I get reads as follows:
“Invalid assignment of property or key ‘priority’ with value of type ‘int’ on a base object of type ‘Nil’.”
I’ve tried referencing the camera normally (I made sure to use @onready), referencing the host instead (which also came back null), updating the plugin, checking if the plugin is enabled, and I’ve made sure that both the camera and camera host are children of the node this script is attached to, so I really have no idea what the problem is.
Is the global a Script or a Scene? If it’s a script it will not have any children, which could be your issue, if so assign the scene .tscn as a global instead.
Just tried it, no luck. Made a separate “game manager” scene because making the game scene global broke everything lmao. I tried both with the camera as a sibling and a child of the game manager, and both didn’t work.
I’m not sure I understand, it sounds like Game is NOT a global. Can you share the whole script of it being used? Maybe a screenshot of the scene tree too?
I think I might have an idea.
When I first added the player_cam and PhantomCameraHost, the plugin wasn’t updated yet
I didn’t update it until those two nodes were already added, so maybe that’s the problem?
I’ll delete the nodes and remake them and see if that fixes the problem
Then did you add the .gd script as a Global or did you add the .tscn scene as a Global?
If you have a GameManager node in your scene then the Global will create another second one unrelated to the one in your scene; you can see this by adding print(get_path()) to your Game_Manager script’s _ready() function, you will have two paths printed. And if you use print_tree_pretty() you may find that only one of them has any children because it was registered as a global script with no children rather than a global scene.
Ok, it finally works
I had already gotten rid of the Game_Manager scene and just attached the script to the root node again, and I guess making the script global was the problem
Since two of the same script existed, one had children and the other didn’t, so it can’t call a child it doesn’t have
And since the game all takes place in one scene that just loads different maps, the root node will always be the same and the script will always be there
(that’s the second time i’ve made a post on this forum that seemed really complicated but actually had a solution that only took like 2 seconds)