PhantomCamera3D doesn't exist apparently?

Godot Version

Godot v4.4.1

Question

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.

(it really is a ghost lmao)

Perhaps a silly question - have you enabled the plugin?

Did you assign the exported variable in the editor? Is Game a global? If so did you assign a script or a scene as the global?

Yes to all 3

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?

For the script of it being used, there’s not much more to show. The rest is code for the player that has nothing to do with the camera.

func _process(delta: float) -> void: #runs every frame or smth blah blah blah
	
	if Input.is_action_just_pressed("back_ability"):
		GameManager.change_cam(8)

Here’s a screenshot of the scene tree:


(the Game_Manager is a global scene and has the script, not the root node. Making the game scene a global literally broke everything lmao)

I think it just genuinely doesn’t think the PhantomCamera exists for whatever reason

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

Nope, didn’t work.

Just tried deleting the plugin entirely and reinstalling it and that didn’t work either

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.

1 Like

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)

Thanks for the help!