What's the best way to avoid an is inside tree error

Hi. Had an issue with a menu selection for changing scenes where I was getting an is inside tree error, presumably because there wasn’t time for the four buttons. I fixed the issue using call_deferred for each of them. Eg get_tree().change_scene_to_file.call_deferred etc for all four buttons but the sub menus on the new scenes are going to be more complex with a lot more buttons, possibly textured, changing texture panels and possibly activating even more buttons. What would be the best way to delay each scene for the amount of time required for its component nodes to function?

FYI I think this error came up after I added a custom font to the project through the project menu but I’m not 100 percent sure.

Anyone have an answer for this? I need to start working on the sub menus.

For one, could you show us your code that throws this error message?
Without seeing that, there’s nothing anyone on these forums can do, since we can’t read your mind.

The error message !is_inside_tree() is true usually means you’re trying to move, modify or otherwise call a function in a node that isn’t actually added to the scene tree yet. If this keeps coming up, there’s something that you’re doing wrong fundamentally in your project, and there’s probably not going to be a “one size fits all” solution to it.
Try to only do processing once _enter_tree or _ready has been called.

3 Likes

I’ve fixed it using the call_deferred on the 4 buttons causing it as mentioned. What I want to know is if there’s a way to do it better than using call deferred. The next menu is going to have over a dozen texture buttons that can toggle. Each of those will bring up 4 - 6 other texture buttons that can toggle. The final result will be a texture panel changing to whatever selection has been made with the toggles. This is essentially a character selection screen for up to 5 characters selected from a large pool and variants of each character also available.

The scene that had the error was only 4 buttons, each changing to a different scene

You would have to share at least some of your code, most nodes will operate inside the tree, maybe you are running a lot of code on the same frame directly after a change_scene_to_file call?

1 Like

Screenshot attached but there seems to be some misunderstanding. I have fixed the errors already with call deferred. I want to know a more efficient way to do it for the next piece of code I write. To be clear, I’m not trying to fix this current piece of code.

Better to paste code than screenshots, especially if you can only fit 4 lines of code on screen.

You shouldn’t have to use .call_deferred on changing scenes, there may be some other issue with your code.

If you want an easier way to connect a lot of button you can connect signals through code or connect multiple signals to the same function with different binds.

That’s all my code is. 4 buttons that change scenes. There is no other code.

I cannot replicate that, are you sure the error comes from these buttons? Are there no other scripts in that scene or the next one?

All the other scenes are completely empty. I’ve got to create all the textures that will be used before I start on them. As mentioned the only thing that stands out to me is that I added a custom font to the project. This is all deck selection for a card game. I could do the textures and code up the next scene to see what happens but I need to photograph cards for the textures. Rather than do a rush job I’d rather wait until I get some hardware so I can make sure the photos of the cards are consistent otherwise I’ll have to waste time recreating the texture files.

Put a print statement or a debugger breakpoint at the start of each of those 4 functions.

Yes there is. You never showed your all your code. Those lines cut off.

You’ve been replying as if you think that everyone should read your mind, and that you know better what your actual problem is than everyone else trying to help you.

You are doing something insanely simple and having a problem. You fixed it in, to be frank, a bad way.

You say you want help for next time, but every request for more information is met with argument or information you were not asked for.

You are new here, and it appears, to programming and programming forums in general. So some advice. None of us get paid to answer your questions. We are all volunteering our time to help people here.

It is appropriate to provide enough information for us to help you. That includes the version of Godot you are using, a description of the problem you are having and what you tried to fix it, and your code. The question template not only tells you all of this, but shows you how to format your code.

You have four people who have replied to you now, who between them have successfully answered over 1,800 Godot questions on this forum. Perhaps you could try trusting that we know what questions to ask, and that we know what we are talking about.

You get out of this what you put into it. And you have put very little into it.

3 Likes

I’m not trying to fix those functions. I want to know how to avoid the error in the first place.

Is English not your first language?

English is my first language. There is no other code that I have written apart from the 4 buttons. I have fixed the four buttons by using call deferred. I have asked if there is a better way to do it rather than use call deferred and nobody has answered that question. They keep focusing on the code I have written. I want to know this for the code I’m about to write. The current code has nothing to do with this situation apart from making me aware this error is a possibility.

Just don’t do what you did last time and you won’t get that error again.

Reading your posts is like watching someone say when they do an addition problem they get 5 and it’s the wrong answer, but no matter how many times you ask them what they’re adding, they just say, “It doesn’t matter, I just want to know how to not get 5 next time!”

1 Like

You said I fixed it in a bad way but you haven’t said what would be a better way which is what I originally asked in the first place. I provided a screenshot of the code which caused the error before I used call deferred but no one seems to think that has caused the error. There is no other code apart from the 4 buttons which are all coded the same and the extends control at the start. I’m creating this on my cell phone so I can’t simply copy and paste without possibly affecting something by accident.

You did not provide the full text of the code. If you can’t copy and paste, then there’s nothing else to do here unless you want to type it in again here for us.

You are assuming that the part we cannot see doesn’t matter. I’m not sure how else to tell you that seeing ? + ? != 5 will never tell use why you’re getting 5.

1 Like

There’s nothing else to see in the code. You can already see 2 of the buttons in the screenshot and the others are coded exactly the same. The path for each scene change is correct using the option given when typing the code eg within the brackets “res://filename.tscn” and the scene changes all seem to function. I have not shown any other code or typed it in because as I have said already, the buttons are all identical apart from the node names and the scene names. There is literally no other code that I have created and the other scenes are all completely empty.