Why my CharacterBody2D not showing?

Godot Version

4

Question

My CharacterBody2D not showing. In a control scene script i type:
@onready var farm_hero = $Character/FarmHero func _process(delta): if character == 1.1: farm_hero.visible = true
but when i start the game and click the button so that the ‘character variable’ be ‘1.1’ and change to main scene but the characterbody2d dont show. Please help

you should not combine @onready var farm_hero = $Character/FarmHero func _process(delta): if on one line
and also make sure you can see it in the editor

i dont have that in oneline idk why its show like that

give me a picture to know better what it is

@onready var farm_hero = $Character/FarmHero
func _process(delta):
	if character == 1.1:
		farm_hero.visible = true

var character:float = 0 
func _on_farm_guy_pressed(): 
	character = 1.1
	print(character)
	get_tree().change_scene_to_file("res://GameScene/Gamescene.tscn")

idk what pic do u want but this is the code when the button is pressed the scene change and the value is 1.1 and if the value is 1.1 the characterbody need to show

Hello, @shiroku! I think it’s a bad code:

func _process(delta):
     if character == 1.1:
            farm_hero.visible = true

You will set visible property at each frame while character equal 1.1.
For your problem, I think, try to use signals for change visible property of your farm_hero.

About singals read more in official docs.

0 is not a float number
and use the custom function you made in delta so it runs in the game

still dont work

still don’t work

try to run the code in another project maybe its not the codes fault
if that doesn’t work you can put the code through a AI chatbot to help you.

nah ig i just found the solution myself

So, please, write the solution here and mark it for another peoples who find a solution.

uh I just instantiate the another scene script



const CHOOSE = preload("res://GameScene/MainMenu/choose.tscn")
var ischaracter = CHOOSE.instantiate()
	await get_tree().create_timer(0.2).timeout
	print(ischaracter.character)
	ischaracter.farmguy()
	if ischaracter.character == 1.1:
		show()
	else:
		hide()

smt like this

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.