godotengine / godot-proposals

Godot Improvement Proposals (GIPs)
MIT License
1.07k stars 69 forks source link

Make it possible to copy a collision polygon from a tileset texture to another #8904

Open mathealgou opened 5 months ago

mathealgou commented 5 months ago

Describe the project you are working on

A 2D top-down shooter.

Describe the problem or limitation you are having in your project

I have multiple levels, and it would be fine to use the same collision polygon certain elements in all of them, but for the kind of variety of elements I'm going for, it's a lot of work just to insert them all one at a time. Take the tileset below as an example:

image

image

It makes a lot of sense in a case like this to have the same walls with another color, another "texture", or other different details in them, but have other objects colide with them in the same way.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

One way to implement it would be by having a right click menu with the options to copy/paste a bitmask. image

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

For copying:

Receive event of copying (I'm assuming the engine uses some sort of event system for things like this, but I'm not sure.) Look at the resource object Store the bitmask values somewhere in memory (Possibly the system clipboard itself)

For pasting:

Receive the event Make asserts to avoid errors (Such as making shure the two textures are the same size, for example) If everything is good to go, put the last copied mask in the place of the current in the texture in which you're pasting Else, show an error message describing what went wrong

If this enhancement will not be used often, can it be worked around with a few lines of script?

Not that I know of, I did try to solve it in a somewhat elegant manner in an addon and faild.

Is there a reason why this should be core and not an add-on in the asset library?

While looking for a way to do this (before I realised there was no way to do it), I've encountered a few people having the exact same problem. At the very least, it seemed like a common issue, and a thing that people (myself included) just expected to be able to do. Also, I have tried to make an extension for this and did not succed.

(On a last note, I'd be happy to help implement this, but since I'm no good with C++, I feel I'd make more harm than good in that case.)

AThousandShips commented 5 months ago

So you mean between the "walls" and the "floor" atlases? Because you can already copy them in the same texture with the "paint" tool, asking because your proposal doesn't make this very clear at all

mathealgou commented 5 months ago

So you mean between the "walls" and the "floor" atlases? Because you can already copy them in the same texture with the "paint" tool

Firstly, thanks for reminding me of the word "atlas", I forgot it, but that's what I meant by "texture". But no, I mean like having a "walls" and a "walls_green" or "walls_red", and just setting the physics layer for one and copying to the others. I've just tried that with the paint tool, and apperently the one thing the paint tool doesn't let you copy is the bitmask, and even if it did, wouldn't I have to do that one tile at a time?

AThousandShips commented 5 months ago

What bitmask? The collision layers?

mathealgou commented 5 months ago

What bitmask? The collision layers?

Yes, the collision layers, more specifically the collision shapes.

AThousandShips commented 5 months ago

The shapes you can paint, what is missing?

mathealgou commented 5 months ago

The shapes you can paint, what is missing?

I've opened the editor to try it, and you can paint, what you can't do is copy. My proposal is to be able to copy all the shapes from one atlas to another.

AThousandShips commented 5 months ago

That's what I asked and you didn't reply with that, you talked about layers, not the atlases, so as I was saying you weren't clear 🙂

that's what I meant by "texture". But no

Good that we've cleared that up

Not as far as I know, but haven't tried it directly

mathealgou commented 5 months ago

Not as far as I know, but haven't tried it directly

Yeah, I've seen a few people with the same problem, once I realised there wasn't a way in the editor, I tried for a couple of hours to write an addon to do it.

I ended bodging a solution that envolves saving the tileset resource as a .tres file, duplicating it, changing the tileset reference directly in the text, and adding some code in the tileset so that I can change what texture resource for another one. It's, let's say, not pretty. image image

image

Thankfully, Godot let's you copy a resource's UID, if it didn't, I wouldn't even have been able to do this monstruosity.