Hello there, first message for me. Happy to be part of this!

I'm having a hard time trying to deal with classes and instances in godot, maybe because i'm too used to object oriented languages (not an expert though, i'm an easy intermediate)

I hope I'm not too dumb in this and didn't miss any very basic notion, but i really tried to figure it out for hours and read a lot of documentation (but maybe read the wrong ones)

The situation : I'm trying to play a character getting inside and outside a house (so through different scenes).

The point is i want to keep the scenes processing while the character is not in, so i'm playing with hide and shows not to reload the scene from scratch everytime the character gets in.

i would like though to queue_free the character from the scene when it gets out so that he doesn't interact with the invisible scene while i'm doing stuffs in the other.

the system i've tried then is to create a "game_panel" script class, from which inherit both outside and inside scene, and that has "_character" as a parameter, which is intended to contain the scene's character's node which I'd like to manipulate (queue_free or set back to spawn point, for instance)

the point is I suppose godot is not working this way since when I try to put for instance in game panel "when getting out of the house, queue_free character", i get a null exception, as in the game_panel class I didn't assign any value to character, since i figured it out as an "abstract" variable to be defined in each scene of the game.

Is there a detail i'm missing, or is my approach completely mistaken to solve my problem ?

Thanks for reading !!

When you say you want the scene to keep processing, do you mean it is actually performing calculations of some description while hidden, or you just don't want it destroyed due to potential momentary lag when re-instancing it? Because if the latter, I think you can just use remove_child to temporarily unload the scene without destroying it and re-attach it when the player goes back into it to achieve this effect.

If you did want the node to stay in the tree for some reason but the location overlap is an issue, I would just dump the top-level node of the house a few hundred units below ground before hiding it and cover it up with a half-second fade to black and back transition animation.

Thanks for answering !

It's not a concern about lag, it's about the fact, for instance, that if I had a clock in the house, it would keep working without beeing rebooted everytime I enter the house.

I somehow figured out something, without being totally satisfied about it.

I used a maybe more "godot compatible" with signals. I just call the add_child(character) very time it enter the house and put it on its spawning point, and do a remove_child every time it goes out. It's kind of working, the point is i'm forced to make the character a different seperate scene, and therefore I cannot put it as a child node of the house scene for instance. I'm not sure as well that if I make any change on the character (change his clothes for instance) it will keep it, i'll try it.

Also for some reason it looks a bit messy to me to proceed this way, but maybe it's a matter of feeling !

"t's not a concern about lag, it's about the fact, for instance, that if I had a clock in the house, it would keep working without beeing rebooted everytime I enter the house.

This sounds like a great candidate for using Singletons

Indeed it looks as quite relevant! I'll check this out and keep you updated. Wonder how i missed it

have you tried adding simple variables blocking movement in the other area?

var terrain = true
var house= false
var characterSide
var characterTop

if terrain == true:
	characterSide = false; character.Top= true
	get_node("house").hide
else:
	characterSide = true; character.Top= false
	get_node("house").show

etc etc

Or u can use the match state fuction, some like this, its incomplete, just for ideas

enum {
	TERRAIN,
	HOUSE
}

var state = TERRAIN

func _physics_process(delta):
	match state:
		TERRAIN:
			moveSide_state(delta)						
		HOUSE:
			moveTop_state(delta)

func moveSide_state(delta):
	# your character side movement etc

func moveTop_state(delta):
	# your character top movement etc 

func _on_houseCollision_body_entered(_body):
	state = HOUSE
	get_node("house").show

@theodeme said: The point is i want to keep the scenes processing while the character is not in, so i'm playing with hide and shows not to reload the scene from scratch everytime the character gets in.

That's gonna be computationally heavy/heavier, and pretty much the exact opposite of what scenes are for, you could say. I'd suggest making one big scene, and then simply zooming in if you want to give the impression that you're a specific place, e.g. inside a house.

More specifically about the clock, you could store the time when leaving the house, and have a variable on the time you are outside the house, and when entering add them together. Alternatively you could just store world time and get the time from that whenever you enter the house.

@Zelta this is more or less what i've came to at the moment. I just hide the scenes I don't need and child_remove the character from the scene when it is invisible.

@cas77 I understand it's an issue, so i've tried to make a mother class from my scene that have a specific method _process_when_active(delta) which computes only the actions needed when the scene is visible (collisions for instance). Because the point is not only for the clock (which indeed would be easy to solve) it's also about, for example, moving the furnitures or leaving objects in the room.

2 years later