The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

Hello,

so i recently started to create my first game with Godot. Today i stumbled across an issue that i would like to move out of my way. So here comes the explanation:

I have 2 functions that kill the player on contact. Those 2 functions go on 2 circular saws each.

func _on_Movable_Saw_1_body_entered(body):
if body.has_method("death"):
    var player = get_parent().get_node("Player")
    $Light2D.energy = 0
    player.position = Vector2(0, 0)
    player.death()

func _on_Movable_Saw_2_body_entered(body):
if body.has_method("death"):
    var player = get_parent().get_node("Player")
    $Light2D.energy = 0
    player.position = Vector2(0, 0)
    player.death()

I need to seperate them because when i duplicate the first circular saw the collision on the duplicated one wont work. Is there a way to just create one saw object that i can duplicate over and over again?

Godot version 3.2.3
in Engine by (15 points)
recategorized by

1 Answer

0 votes
Best answer

If you right click on the saw's root node in the scene panel there should be an option like save branch as scene. This will save your saw as a scene file which can be created from that file in any other scene. Kind of like a prefab if you're coming from unity. If you make a change to the saw's scene file, that change will be applied to any instance that is being created from that file. But if you make a change to one of the instances, it will only affect that one saw.

You can edit this scene file just like any scene file, so open it up. Connect the on_body_entered signal to the function on itself. Now any instance of this saw will call that function on itself.

Click on the chain link icon on top of the scene panel to display all your scenes. Click the saw scene file to create an instance of it in your current scene.

by (130 points)
selected by

Thanks for your answer it is working ^^

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 Frequently asked questions and 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 [email protected] with your username.