0 votes

I would like to use a specific node of a different instance within another seperate node, but don't really know how to go about doing it properly. The following statement I have resolved to use seems "hacky" and would love to hear a proper solution:

instance.get_node(old_node).replace_by(preload("class.gd").get_node(new_node), true)

The reason I am trying to do this is because I have multiple colour variations of the same sprite. And for each colour variation, a version of all animations associated with it (The animation is the same for all of them with the only difference being the colour of the sprite). I have separated any node data relating to each colour variation (AnimatedSprite Nodes) into separate instances (scene files), and would like to "import" whatever node data is necessary for the colour I choose to select within a separate script.

I think my question stems from a lack of understanding as to how GDScripts and Nodes relate to one-another, as well as to how to effectively use them together.

This is my first game with Godot, so I'm still trying to get my bearings with how to develop a game within the engine, as well as developing games in general.

Any help and suggestions would be definitely appreciated!

in Engine by (30 points)
edited by

Looking around the docs have helped clarify the relation of the script and the node. Though the question still stands really.

Why would you need to have duplicates of the same animation if the only difference is colour?

Honestly I don't know how to programmatically do it within Godot so this is how I've been logically doing it until I figure that out. I'm open to alternatives. If I could change the colour of the resource image that would be fantastic. I'd just use one sprite and change the colour.

There should be a modulate feature on sprites which will change the overlay color of the sprite. Not sure if you want different colored shirts though since the modulate affects the whole sprite I believe. You could have different textures for each color (copy the same sprite sheet and change the color of the shirts or pants) then write in your script to change between the sprite sheets when you need to change the color.

If you need to change colors a lot and don't have a set color variation aka red, purple, blue, yellow teams and want something more like a RGB range, you can separate the parts you need to change color from the main sprite. Example: You want to change the shirt color only on the sprite, make a sprite sheet with the character excluding the shirt area, make a sprite sheet with just the shirt, have 2 sprite nodes, modulate the shirt sprite node to whatever color you want using the modulate property.

This is actually great. The sprites I am using are of two colours, super simple. I have 5 different colour variations one of which is white. Modulating on the white sprite allows
me to represent the other colours. Thanks a lot for the suggestion! Makes this question moot.

1 Answer

0 votes
Best answer

In the comments ^
Didn't answer the question itself, however suggests a different method to go about doing what I was trying to do.

by (30 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.