What is the correct way to scale shape instances

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mromnia

Hi,

as far as I could gather from the documentation and various other answers, you’re not supposed to (and sometimes even can’t) directly scale shapes through the scale property. At the same time, shapes are resources, and thus are shared between all instances of a scene.

I want to make a reusable scene that includes a body with a shape and a sprite. I intend to instance this scene multiple times in my main scene, but I want it to have various sizes. So my perfect scenario would be that every time I instance the scene, I can scale each independent instance in the editor.

However, that’s not really the case. Some body types outright don’t scale (RigidBody2D), some scale but work… strangely (StaticBody2D), some seem to be fine but probably are broken in some subtle way (Area2D).

So basically I’m asking if my perfect scenario is achievable and what’s the pattern for it. Keep in mind I can’t directly resize the shape, because it’s shared between all the instances which I want to scale independently.

Thanks for help!

If you can’t scale shapes but resize them, you have to make them unique, isn’t it? That defeats reusing… I’m sure moving objects can hardly be scaled dynamically, but static objects might in some physics engines, at least uniformly, keeping their normal aspect (i.e no weird squeezing when scale comes from multiple parentings).
In Godot though, unless I miss something (I never scaled bodies myself and preferred using other approaches), I’ve always seen “don’t scale bodies”, so you either have to make shapes unique and resize them (I know it’s annoying), or wait/ask for scaling support for staticbodies.

Zylann | 2018-05-09 12:36

I want to reuse all the logic connected to the scene, but be able to change some properties. Just like when you’re using sprites, you reuse the concept of “sprite” but change it’s position, scale etc.

Could you elaborate what are “other approaches”? I’m not saying the only way is to scale shapes - I just want to be able to configure the size of my scenes.

Stupid example: in a platformer, I have a special kind of floor segment. It has some logic connected to it, obviously it has a body and a sprite and perhaps a milion other nodes, so I don’t want to reimplement it every time. But I want the floor to sometimes be x long, and sometimes 1.5x long. Can I achieve that while keeping the reusability?

EDIT: Also, is it even possible to make shapes unique per scene instance? And if it is, are there some performance drawbacks to it?

mromnia | 2018-05-09 13:14

You can edit just the shape for a particular instance by making its children editable (right click on the node). Then navigate to the shape and make unique.
If you have a fixed amount of variations, you can inherit it as many times as you have variations, just change the shape in the inherited scenes and use that as several templates.
If you need too many variants, you may have to use editable children and do that on per-case basis, use a more modular approach with tiles, or eventually tool mode in last resort if you need maximal flexibility and automation (I did that for laser walls in my game because changing their size involved resizing multiple things at once).
But again, I didn’t have this problem often so that’s just some ideas from what I know.

Zylann | 2018-05-11 00:06