How to CHANGE SCENES in Godot | ARPG S02E02 | tutorial | GDScript
Вставка
- Опубліковано 1 лип 2024
- In this video we will be looking at how we can change the scene in Godot.
What problems that we might encounter and how we can fix them.
Support the channel on Patreon: / makertech
Support the channel with a UA-cam membership: / @makertech
Join the Discord server: / discord
How to Make an Action RPG in Godot season 2: • How to Make an ARPG Se...
How to Make an Action RPG in Godot season 1: • Action RPG in Godot 4 ...
00:00 Introduction
00:30 Creating the House
02:39 The New Scene
03:52 Scene Trigger
10:03 Scene Manager
14:07 Base Scene Script
21:18 Entrance Markers
25:26 Final Tricks
---------------------------------------------------------------------------------------------------------------------------
Download Godot: godotengine.org
"Ninja Adventure" asset pack: pixel-boy.itch.io/ninja-adven...
My additional assets pack: makertech.itch.io/additional-...
---------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------
Reddit: / makertech
Instagram: / makertech_dk
Twitter: / makertech_dk
UA-cam channel: / makertech
---------------------------------------------------------------------------------------------------------------------------
#gamedev #godot #godotengine #godot4 #tutorial #zeldalike #learntocode #howtomakeagame - Наука та технологія
I agree with you that that you shouldn't just skip ahead to the final result. It's good to show things like mistakes or code that evolves and needs to change. A lot of tutorials don't go into the thought process enough to teach beginners fundamental programming skills like problem solving. If you just going to show someone how to code / make a feature and they don't know why they doing it then they not going to be able to transfer that skill into other things they do. All they will learn is how to make a feature in a very specific way.
Thank you so much for the comment.
It really means a lot.
My goal really is to try and teach good software engineering principles with hands-on examples of what real life development is like.
I think this video taught me more than just scene changing. Before I wasn't sure how to go about not making a new script for every room I wanted to go to, but now, I know the method of changing it in the inspector which is really useful for multiple nodes. Thank you so much.
I'm saying it again---You're one of the best, if the not the best, Godot teachers/tutors on the web.
I still can't believe these videos are free to see. Thank you for that.
Thank you so much for the feedback.
It really means so much to me :)
I am really trying to keep everything free as long as possible.
Anyone struggling with Player part: make sure your player script has a class name. For example, my player. gd script starts with "class_name Player extends CharacterBody2D" on the first line (minus quotes).
AHH you have no idea how much I struggled to figure out why the scene transitioned immediately upon beginning play whether I was using a simple area2D or an autoloaded area2D with signals. Thank you once again for your tutorials, wish I had just started here earlier...
I'm glad you liked the vidoe and found it helpful :)
thank you so much! I was wondering how to fix that. the scene_manager script giving me the error that it could not locate the name Player. giving that class_name to my player script fixed it immediately! btw, I'm using Godot 4.2
Great video, thank you! I wouldn't worry too much about people being too impatient for these longer ones, as you said the iteration is part of the process, and learning to take that step back and look at the wider changes you need to make is a crucial skill to learn. I'd go so far as to say NOT learning how to do that is why so many people get stuck just copy pasting from tutorials and not being able to go any further, so you're doing us all a big favour with this format!
Thank you for the feedback, it means a lot :)
I'm not really to worried about it.
I just try to make a huge point out of why we do it this way.
Because it really is so important to understand if you want to really learn any kind of software development.
Thank you for this, I was just struggling on how to design/implement a scene transition manager and your video filled that knowledge gap perfectly. It's very easy to follow and to iterate upon, and the way you narrate the script is very straightforwar and to the point. Keep up the great work and thank you for everything you do.
I'm so glad you could use the video.
I was a bit worried it was getting too long.
But at the same time I didn't feel like I could leave anything out or divide it into smaller pieces.
@Maker Tech maybe you could make a video on how to make settings/options menu - video - resolution window options, audio, rebinding controls and more? You could make tutorial on how to make main menu and menu for loading saves of game.
Hi, and thank you for your input.
I think I have most of your ideas on my (long) list of video ideas from viewers already.
You can always see what I'm working on for the channel at my public Trello board: trello.com/b/kbbA5lIf/maker-tech-public
LOVE IT! Thanks Maker Tech
Thanks, I'm glad you like it.
THANK YOU VERY MUCH, SUCH A NICE TUTORIAL! 😁😁
thank you so much for your tutorials!!!!! makes learning the progam a breeze
Hi and thank you for the feedback.
I'm really glad you find the tutorials helpful :)
Such a wonderful tutorial.
Thank you so much for the feedback.
I'm glad you like the video :)
Liked and subscribed! Thank you!
Awesome, thank you!
i'll give this a try tomorrow! I hope this works with Godot 4.2 😅i really want to have multiple scenes to go into like you showed in your video. If this works on my end, I'm definitely going to use this A LOT. Thank you so much for making this video! I asked the Godot 4 community and people just seemed confused as to why my code wasn't working.
Hello.
I just want to say that as a newcomer to Godot, your way of showing and telling is absolutely perfect. You should have been a teacher :) Take it as a compliment :-)
I have been following your videos now to make a simple game with my two daughters and I am wondering about one thing. Instead of going through the door, is it possible to get [E] up to open the door? And animate the door too :-)
Hi there and thank you so much for your feedback.
I actually have a teaching degree.
Later I also worked as a teaching assistent when I studied software technology and computer science at uni.
And I'm homeschooling our two daughters.
For your last question.
Yes you can.
The trick is to figure out how ;)
Maybe start by figuring out how to check if 'E' is pressed while the player is within the doors transition area...
Thanks!
And thank you!
I'm glad you liked the video :)
Using Items and deleting them from inventory seems a good addiction to me
That is exatcly what I'm working on today :)
@@MakerTech :)
I do get pretty addicted to inventory management 😂
(sorry couldn't help myself)
nice
I always thought you'd have a main scene that never changes with the player and gui attached to it, and a level/world scene that's a child of the main that you could just swap out without having to re-instantiate the player and gui... is this still a viable option? To me it sounds better but I'm often wrong about these things, your thoughts?
You can do that as well.
I do that in a lot of cases as well.
I actually considered showing that solution instead, but ended up with this one because I felt it would be the easiest to get started with.
I'm having trouble with the camera. My other scene needs the camera but if I walk into the next scene I'll get errors
Hi, I have a problem with a Player that when its change scene the error said that Node not found "Player" in inside house Scene
func _ready():
if scene_manager.player :
print("Have Player")
if player :
player.queue_free()
player = scene_manager.player
print("Player in Scene")
add_child(player
and when i enter a scene_trigger its print out like this. I dont know why is not found when the system print like this
Have Player
Player in Scene
Hi there! Have been going through yours tutorials to use it in my own game but just found a problem now. Don't know if you can help me? I place the trigger where I want my player to appear but he appear in another place, however ir always in the canvas normally. I am not using follow cam, just doing scenes that fit the game screen. I want to make him appear in X place because of the door etc would be better if someone is playing. If you have an idea of what is causing this pls tell me and again THANK YOU VERY MUCH!!!!
Hi there.
Did you find a solution to your problem?
If not, then you can also join the Maker Tech Discord server.
It is usually a lot easier to help out on Discord and similar places, than in these comments on youtube.
I just got my way out from "invalid get index 'player'" error but the next line " player.get_parent().remove_child(player)" reports that it cannot call the get_parent( ) function with a null value. Anyone know how to solve this?
same problem here... if anyone have a solution would be great
For me I had to add the super() to the _ready function of each level
@@Bigmaster220 I had the same error here, but I dont know how did you solve it. What do you mean exactly?
how do you full_path in Godot
Hi, i really love the tutorial. I just have a question about your player. Is it instantiated in the main scene? When I follow this tutorial, the from.player is null for the node2d. I was trying to find your code for the player node to check, could you direct me? Thank you
The player is instantiated in the main scene, yes.
And since we added and onready variable to hold the player in the script for the base scene (that all other worlds/houses/etc. will inherit from), the player should really be instantiated in all scenes (this also makes it easier to test individual scenes).
@@MakerTechThank you for the quick reply, thats very helpful. I thoiught your tutorial was great, just got snagged on that part. I've liked and subscribed and will be back to watch your other vids. Keep it up. (When you say the player should be instantiated in all scenes, does that mean that at the base scene, the player always exists, and what we're doing in the tutorial, is just switching between scenes and copying over the player from the base?
@@NUTTY-nw4ed All our worlds/places has either the base scene script or a script that extends from this.
So they all have their own version of the player when they load.
But we then remove this original player and replace it with the one from the previous scene, when we change scenes.
So in reality we only every use the player from the very first scene we are playing in.
Hmmm...quick question; Would this method allow the current state of your health to be transferred to the new scene? I cant see the GUI in the house segment so I figured i'd ask before trying the autoload method over the other(s)。✌🏿
The player is a part of the player scene, so yes it transfers.
I just didn't add the gui items to the scene for the inside of the house, that is something for you to explore :)
@@MakerTech Arghhh 🦜...okay, heh。 Thanks! 🕹️
👍
Hi :) Its my first time creating game and your videos are really helpful. However, I have this problem "Invalid set index 'global_position' (on base: 'hull instance') with value of type 'Vector2'" I encountered this when changing scenes huhuhu by any chance do you know how to fix this? Thankiesss
The 'null instance' error tells you, that the object doesn't exist.
So you would have to find out why the object you are trying to set the global_position for isn't there.
I'm guessing it is the player?
Maybe it isn't set correctly from the old scene before the change?
Hiiii I'm having the exact same problem! Did you ever figure out how to fix it?
In Scene Manager Script, What is "var player : Player"? I can't find "Player" type
Did you figure it out?
It is just the custom player class (scene) used for, well the player.
This is late but for anyone else reading, make sure your player script has a class name! Example: "class_name Player extends CharacterBody2D"
@@MCNeko6554 you saved me so much heartache thank you
спасибоооооо!!!!!!!!!!!!!!!!!!!!!!!!!
If you love this arpg tutorial please drop a like so the newbies can see how much people love it!
Hey I think I made a mistake placing something or in the code but I get an error "Node not found: "Player" (relative to "/root/InsideHouse")" . wanted to know if you could help. Thank you
I also cannot move the player at all in this state when i go into the room
Did you find the problem?
It sounds like you either did not add an instance of the player to the scene for insider the house.
Or maybe the player isn’t at the correct path in the scene tree.
Great video. Do you make the code available? I searched for a github but found nothing.
At the moment it is only available as a reward for some of my patreons.
@@MakerTech That is fair enough. Your videos are very helpful, so thank you.
In this particular video I would suggest two things:
1. You are right that scene transitions are going to be many and varied but town-door transitions are going to be very much the same each time. Rather than redraw the collision shape for each of those I would create a town-door scene and instantiate. There are bound to be quite a few.
2. Building file paths the way you are doing restricts your scene manager to that path. It is just as easy or even easier to just drag the complete file name from the file manager into the code window (or into the export variable). So if you want to transition to a scene that is not at the standard source path you don't have to build a separate handler for it.
Sure there are a lot of ways to handle scene changes like this.
I just try to give an open solution that people can then expand on as they wish (or simplify it that fits their game better).
This tutorial was very helpful. I found out about the persistent player problem in my own game when I changed my scene and the player reset. Your solution fixed that issue and I was very excited until...how do I keep the old scene persistent. The player doesn't reset anymore but the scenes do. Items that have already been acquired, like zelda heart containers, respawn.
Depending on how many scenes your game has, and how big they are, you most likely don't want to keep all scenes loaded after you leave them.
In this case what you need is some way to save the state of a scene when it leaves scene tree, and then load it back in when it enters the scene tree.
LOL I did come up with an idea for a solution but it isn't very satisfying. I am basically going to have an array of bools has_heart[index]. If the player has that heart I will queue_free the heart item instance@@MakerTech
12:12 what does var player : player and player = from.player
var player: player refers to the class_name player (which is the class name given in your player script). Which means if you use this code from the video, your player script extension should look like this: class_name player extends CharacterBody2D
As for player = from.player....i'm just as confused as you are tbh..
I noticed this video tutorial is not really compatible with Godot 4.2
@@tomoyaokazaki2138 This tutorial is plenty compatible with 4.2.
To clear up the misunderstanding player = from.player is passing in the player from the previous scene. That way we can utilize it later in the most current scene.
I keep getting the error 'invalid get index 'player' ' from the line 'player=from.player'. Am I doing anything wrong?
Did you remember to add an onready variable to the base scene script?
Maybe try watching the video again and make sure you understand each step before moving on to the next
@@MakerTech Im getting the same error too, it happens in the scene_manager script before we write the base scene script
@@ian3857 Then you need to look in the script for the scene you are moving away from. It has to have a variable for the player for this to work.
@@MakerTech Hey thank you! It worked im on to the next part of the video. Thanks for making these tutorials
@@ian3857 Great!
19:58 what have you done in this part ? :(
"Select the camera and add the player in the inspector menu"
@@MakerTech Hiii i did but i have this error(Node not found: "Player" (relative to "/root/InsideHouse") still working on it
The error tells us, that you don't have an instance of the Player class added as a child of the InsideHouse scene.
Are ungirl
???
this is extremely confusing for a beginner because of all the going back and forth. genuinely don't understand why you couldn't have done it right the first time and just go over mistakes naturally as they happened. wasted my time with this video.
I'm doing the videos in the same order, as I would normally develop the solutions.
This is on purpose, because the most important thing, if you really want to learn game dev, isn't to just get the solution and understand it afterwards.
Instead it is to experience and understand the process itself.
Also, changing scenes like this isn't really a simple a task as one would hope.
So in a lot of ways it just isn't a very beginner friendly topic - at least not if you are also new to programming.