I am trying to prototype animations in Godot . However I am using procedurally generated diagrams. I am calling the _draw() function and other draw calls to create these diagrams. The animations work great but I can't preview them in the editor, which is a hassle. Even using the @tool , the node doesn't update to show the drawing in editor. Is there some way I can live preview the node and its keyframes in the editor ? or maybe animate while running the scene ?

  • xyz replied to this.
  • druboi Is your _process() running in the editor?

    druboi Is your _process() running in the editor?

      when you set @tool in script, save script, close the tscn file and open it again. otherwise it wont start to process it

      xyz
      🤦 I have to call queue_redraw() in the _process() function.
      It is working now !
      I was calling redraw() from the call method track.
      I have a sickness, I keep trying to go easy on my gpu 🤪.
      Thank you again !

      Is there a way to call a method in the AnimationPlayer for every frame in a time range ?
      I can simulate the same by calling a method to toggle a boolean and letting the required method update in the process() but can I do so directly from the AnimationPlayer , so I don't have to toggle on and off every time ?

      • xyz replied to this.

        druboi No, because animation player doesn't deal with frames.

        xyz

        I have a similar issue with live previews while using a Sprite node whose texture is created by load_svg_from_string() method. Can I view the sprite in the editor with @tool ?

        • xyz replied to this.

          xyz
          The sprite doesn't show in the editor , it shows when the scene is run. Is there some method I should be calling in process() to update the scene ? I went through the @tool docs , doesn't mention anything.

          I checked , the editor is updating however the sprite is not.

          Even creating texture from an non-svg image file also doesn't show in the editor with @tool

          • xyz replied to this.

            xyz
            Here is the zip of the script :

            svg-testgd.zip
            1kB

            The output :

              druboi why didnt you paste the code in here ? use ``` tags at the top of the scrip and bottom so that the script formatting stays

                kuligs2
                Sorry I thought , this would be more convenient , I'm new to forums in general , I'll paste the code here if that is the norm.

                @tool
                extends ColorRect
                
                @onready var shape_sprite1 = $Sprite1
                @onready var shape_sprite2 = $Sprite2
                
                var svg_str = """
                <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" width="100" height="125" viewBox="0 0 100 125" enable-background="new 0 0 100 100" xml:space="preserve"><path d="M84.548,13.463c-2.621,3.618-5.332,7.163-8.079,10.68C61.895,9.028,36.034,10.908,18.634,19.39  c-1.735,0.846-0.217,3.426,1.51,2.583c17.643-8.599,39.176-8.981,54.388,4.657c-10.094,12.744-20.814,24.981-31.25,37.456  c-4.515-4.647-6.024-12.084-6.924-18.2c-0.642-4.36-7.245-2.499-6.609,1.823c1.336,9.079,4.384,18.718,12.237,24.135  c1.171,0.808,3.231,0.571,4.152-0.535c10.946-13.174,22.245-26.047,32.91-39.435c8.343,12.937,2.167,30.542-7.992,41.167  c-10.522,11-27.784,14.038-42.07,10.313c-24.049-6.27-17.528-32.484-6.895-47.676c1.11-1.585-1.486-3.079-2.583-1.51  C8.684,49.628,2.425,71.21,21.227,83.276c14.998,9.626,37.018,4.139,49.898-6.24c14.162-11.413,19.197-31.953,9.65-47.349  c3.307-4.195,6.551-8.436,9.69-12.766C93.064,13.335,87.114,9.921,84.548,13.463z"/></svg>
                """
                
                var val : int = 0 
                # Called when the node enters the scene tree for the first time.
                func _ready() -> void:
                	
                	var image = Image.new()
                	image.load_svg_from_string(svg_str)
                	image.fix_alpha_edges()
                	image.premultiply_alpha()
                	shape_sprite1.texture = ImageTexture.create_from_image(image)
                	shape_sprite1.position = size * 0.2
                
                
                	var image2 = Image.new()
                	image2.load("res://Darkness.png")
                	shape_sprite2.texture = ImageTexture.create_from_image(image2)
                	shape_sprite2.position = size * 0.5
                
                	pass # Replace with function body.
                
                # Called every frame. 'delta' is the elapsed time since the previous frame.
                func _process(delta: float) -> void:
                	pass
                • xyz replied to this.

                  druboi When do you expect the update to happen? Since you're doing it in _ready(), it'll happen only when _ready() is called. Inside the editor, that's only when the scene is loaded or the named script class instantiated. Put a print statement in there to see when it has been called. You can trigger it if you close the scene and open it again. Note that it won't happen if you only detach an re-attach the script because the node is already in the tree (already ready 🙂) so _ready() won't be called in that case. Check the documentation on _ready() if you're interested in more details about how/when it's called.

                    xyz

                    OK ! I get it . That is why these are called scripts ! They are run on the fly for a the node they are attached to. I was expecting that they are used to instantiate the nodes like classes in Object oriented programs do , every time I make a change. Rather Godot just calls the scripts at runtime for the associated nodes . If I add a new method , then that new method is called but the _init() or _ready() isn't. Very cool but also slightly counter-intuitive. That is why commenting the @tool also doesn't pause the live preview also.

                    There is an option in the command palette for reloading the scene. This reflects the changes and re-instantiates the scene tree with the updated script.

                    This will be very helpful.
                    Thank you !

                    • xyz replied to this.

                      druboi Scripts can in fact instantiate nodes. They are precisely analogous to object oriented classes. If you add a new method to a script, it won't be called if you don't explicitly call it. Unless it's one of the special virtual methods that engine calls "automatically" under certain conditions, like _process() for example. The _init() method is equivalent to a standard OO constructor, while _ready() acts as a sort of a constructor for nodes in the scene tree. Toggling the tool status of a script might not take effect immediately, so best to reload the corresponding node(s)

                      To reload the scene, simply close its tab, and then double click on its *.tscn file in the FileSystem panel.

                      There's the "soft reload tool script" option you get when you right click on the script file in the script editor, but this still won't call _ready() for already live nodes the script is attached to. You need to force reload the node itself. Because _ready() is called, if available, when the node finishes its scene tree entrance, not when a script is attached or instantiated. Only _init() will be called in those cases.