My character won't spawn in

Godot Version

4.2

Question

I wanted to learn how to make a respawn point, so I followed a youtube tutorial and ended up learning about initializing the character. When I implemented it however my character never spawned in the first place, and the camera on the player is directed to an empty void, I deleted the script and yet my character still won’t respawn.
I decided to make a whole knew project without initializing my character and instead just putting them in the world and resetting the world when they die. But they still won’t spawn? Maybe it’s because I copied the character code from my last project but I can’t understand why this is happening.

Which tutorial did you follow?

initially I followed this one

The code is fairly straightforward and simple. I generate lots of game pieces in my merge game.

You haven’t given us any code to look at.

It’s a 3 step process. The Player Scene needs to be :

  1. Instantiated and added to a variable to hold the object.
  2. Added as a child of the appropriate parent.
  3. Visible and positioned in view.
1 Like

This is my current player script (It only lets me upload one image per post annoyingly)
I restarted my project and removed initialisation and instead just went with resetting the scene, but either way my character is still not loading when I play even though I’ve put them in the scene, I can’t tell why.

The problem starts at the very top.

@onready var anim = get_node(“AnimationPlayer”)

In the video @ 1:04 he uses:

var player_scene = preload(“res://scenes/player.tscn”)

In my own game, I use

var game_piece = preload(“res://game_piece.tscn”)

This line preloads the scene as a resource into the variable.

get_node gives you access to the active node’s properties and methods, but your animation player isn’t active yet. It needs to be INSTATIATED to be active.

In the video at 1:33, he types

var new_obj = player_scene.instatiate()

In my game, I have

var p = game_piece.instantiate()

Then in step #2, you need to add the instance to the parent. Since I’m calling this from the game_board where the piece is placed, it’s simply

add_child(p)

In the video at 1:55 he add the player to the parent

get_parent().add_child(new_obj)

At no point in your entire code do I see …

instantiate()

Or

add_child()

yes there is no Instantiate() because this is my script for after I got rid of that, I have it to reload the scene on player death/entering a death plane, the player is simply in the scene and yet will not load when I play the scene

Is player in the scene when it loads initially?

No, and if I put a camera 2d on the player, it doesn’t show the scene instead it shows basically an empty scene, the player is not in either.

I haven’t done anything w cameras so I don’t know what putting “a camera 2D on the player” means.

In your project settings under Display → Window, is the entire viewport height and width smaller than your monitor size? I had an issue with the top and bottom of my scene being cut off because I was trying to size the scene for a cell phone, but that’s taller than my monitor’s resolution.

Is the player in your 2D view placed within the viewport box?

Do you ever make the player.visible = false and never turn it back to true?

Do you initialize player.position within the scope of the game window?

Why did you get rid of the instantiate code?

Have you looked at your Node tree during runtime to see if the Player node is there or not?

A camera 2d shows and follows the movement of its parent, so if you have a camera on your player, the game will follow the player instead of being say at a set distance showing the whole screen. the viewport is fine, I assumed player position would be set by dragging the character into the scene is that not the case?

I got rid of my instantiate code because my player character would spawn for about one frame and then disappear, if you know the reason for that too that would be great!

how do I “look at my node tree during runtime”?

how do I “look at my node tree during runtime”?

During runtime either on a separate monitor if full-screen or swapping back and forth between the windows or (in my case) sliding the game to the side, the scene tree changes from
godot_edit_view

to
godot_run_view

If you click REMOTE, it’ll show the scene tree dynamically created to show your game in action while it’s running.
godot_remote_view

All those @Nodes at the bottom are added in via code.
Each cell in my code is added via code. Each game_piece is added via code.
Since my game board currently has 63 cells, I’m working with up to 126 child nodes.

1 Like

I got rid of my instantiate code because my player character would spawn for about one frame and then disappear, if you know the reason for that too that would be great!

It sounds like you put your instantiate code in the wrong place, or you had another line of code that was acting against it.

F9 sets a stop in your code so you can go line-by-line (F11) or resume (F7) until it gets to the offending issue.

Since frame rates of Godot games is ~1/60th of a second, I’m thinking that you were doing something in your _process(delta) function that was despawning him. OR you were moving him outside the viewport area in some fashion.

In the video example, the character despawns when it encounters the black tiles. If you spawn the character on a tile that’s also a killing tile, it would spawn and immediately despawn.

What code did you have to despawn him? What conditions had to be met?
Did you verify that it was behaving properly?
Was there a trigger that was getting accidentally set or not getting reset?

1 Like

That’s what I understand, but I don’t do that. I instantiate my pieces and position them dynamically.

1 Like

The despawn code was just to free the player from the tree when they touch a death plane, which is just an area 2D I put in group “DeathPlane” it was definitely working before I added anything else because I tested throwing my character into it and they would despawn

I’ve figured it out thanks!

Glad I could help.
What was the issue?

1 Like