Hello! I made a door scene that I can add to my maps to transition to other levels when clicked. The transition logic is inside this door scene, but I would like the doors to have different sprites. The problem is I can't change the sprite individually for a instantiated scene. I would also like to give them different animations on mouse hover. Is there a way to do this?
Make changes to instantiated scenes?
xyz Do you mean there is a way of accessing the nodes inside an instantiated scene through get_node() at run time?
That would make it difficult to position the doors how I would like. Let's say I want a big medieval door. All the logic should be the same as other doors, but I want the sprites, positions and area2D to be different. It would be a lot harder to do this by code, instead of just positioning it inside the scene.
Is there a way to "export" the sprite and the Polygon area? If not, maybe I just need to make a superclass that can pass the logic, and create the doors individually inside any scene...
- Edited
Godoten There's no "instantiated scenes" at runtime. Once you instantiate a scene, it becomes a regular clump of nodes. When you add its top node to the main scene tree, the whole thing becomes just an ordinary branch of the scene tree. You can access any of its nodes via correct relative or absolute paths. Check the remote scene tree at runtime to see the actual live situation. The scene tree doesn't really know or care which of its branches were instantiated from "scenes"
Interesting! I could access the inside nodes of the instantiated scenes through the "Remote" tab. But how do I modify them? They disappear when I stop the game.
You need to keep a reference of the door, to access it (easier that way). Make a variable or a array of doors, put it there and then when you need to change something just take it from that array
- Edited
Godoten The solution to this is very simple
just go to your main door scene and then click on the parent node and copy it, then open a new scene and click the "paste from clipboard" button that should appear in the node tree, you should have a 2nd copy of your door scene now, change the name of the parent node in this 2nd door scene to something else, and then save it as a new scene, and you can even attach a different script to this 2nd door scene that's different from the first one
and yeah now you have 2 different door scenes that are completely independent from each other, you can give each one different sprites and different animations and different code and everything
buzzbuzz20xx Better to use inherited scenes if there is a need to preserve editable shared functionality.
xyz inherited scenes make my head spin XD I'd rather just copy paste everything haha, been working fine with me
buzzbuzz20xx inherited scenes make my head spin XD I'd rather just copy paste everything haha, been working fine with me
... until you have a lot of variants and need to make frequent adjustments to common functionality parts
xyz oh yes that's gonna be an issue ! I should probably learn more about inherited scenes and how to use them