#Help with Memory and Tweets

1 messages · Page 1 of 1 (latest)

austere echo
#

I have a level node, for which I have many (10 for example) hazards which are controlled by the current code.

When the player enters the room start_movement() is called for all the hazards and when the player exits the room start_movement() is called on all the nodes.

Playing in Godot seems fine, but the version I just pushed to itch seems to be very memory hungry

Have I got an issue with my memory management here?

link to game: https://supersingular.itch.io/blink

itch.io

A platforming game where jumps change as you chain them together.

#
extends StaticBody2D

@export var horizontal: bool = true
@export var distance: int = 0
@export var move_time: float = 1.5
@export var wait_time: float = 0.15
@onready var sprite: AnimatedSprite2D = $Sprite

var is_reversed: bool = false
var start_position: Vector2
var end_position: Vector2
var tween: Tween

func stop_movement():
    tween.kill()

func start_movement():
    position = start_position
    _move_spikeball()

func _move_spikeball():
    tween = get_tree().create_tween()
    tween.bind_node(self)
    
    tween.connect("step_finished", _on_step_finished)
    
    tween.set_trans(Tween.TRANS_LINEAR)
    tween.tween_property(self, "position", end_position, move_time)
    tween.tween_property(self, "position", end_position, wait_time)
    tween.tween_property(self, "position", start_position, move_time)
    tween.tween_property(self, "position", start_position, wait_time)
    tween.set_loops()

func _on_step_finished(step: int):
    if horizontal:
        sprite.flip_h = (step == 0) != is_reversed if step in [0, 2] else sprite.flip_h
    else:
        sprite.flip_v = (step == 0) == is_reversed if step in [0, 2] else sprite.flip_v

func _ready() -> void:
    start_position = position

    if horizontal:
        sprite.play("horizontal")
    else:
        sprite.play("vertical")
        
    start_position = position

    end_position = position
    if horizontal:
        end_position.x += distance
        if end_position.x < start_position.x:
            is_reversed = true
    else:
        end_position.y += distance
        if end_position.y < start_position.y:
            is_reversed = true
        
#

Otherwise, if this isn’t an issue, how can I look at memory allocation in debug mode?

crisp schooner
#

given this is just an infinite looping tween (would never be emitting finished and freeing itself while the node exists) - you could just start and stop this instead of creating a new one (tween.pause(), tween.play())
also - you don't really need to tween end position to end position and start to start to create a delay -- tween.tween_interval(wait_time)

austere echo
#

When you pause the tween does it pause on a step or can I force start to begin with step 1?

crisp schooner
#

you would stop() to go back to the beginning, pause() should stop at the point it stopped at

austere echo
#

I think I need to monitor memory management closely anyway tho… at the moment I don’t know how to detect leaks and with such a small game having my browser crash is worrying 😕

#

Aside from those nice tips? The other option I suppose would be somehow only loading in the whole level as the player enters the node but I don’t know how to do that

#

At the moment I have a Node2D called Levels and then the children of this node are all the levels one after another

crisp schooner
#

they're all loaded together? instead of being split into individual scenes that you load as you move to them?

austere echo
#

Yeah I have a world scene with 10 level scene nodes as children

crisp schooner
#

yeah for memory management i'd try not loading the entire thing at once - if a level isn't being interacted with right now, you probably don't need it loaded in doing things
ie: you load up a section of the world - when you hit a point you're going to transition to another level, you then load in that next level and unload the one you were just in (ie: instantiate the new level, queue_free() the old one)

austere echo
#

To instantiate it I need all the level scene path names then?

#

The levels are so small I figured it wouldn’t be an issue — 320 x180 rooms

crisp schooner
#

would be good to have, or you could set that up as an export on the transition points

#

ifi t's all the same assets - it might not be quite as bad, but if you have a lot of things actively doing logic because they're loaded in but are quite far away and can't even be interacted for quite some time, doesn't quite make sense to leave them to their own devices

you could theoretically - just turn off processing on all the additional levels until you enter them by changing the processing mode of their root nodes

austere echo
#

Do you know how to check memory profiling in debug? I saw something for graphics and physics engine stuff but nothing for memory?

#

With level_one.set_process(false) / true

crisp schooner
#

i was thinking more changing the mode - ie: set_process() might turn off that node's processing, but i don't know if that will inherit down the tree
set_process_mode() is something that other nodes of that part of the tree should inherit if their mode is set to inherit