Closed stickynoteme closed 3 years ago
Strange. In my personal project and in the examples like Typical2DPlatformer, the position for entities aligns as expected. Do you have any Gameobject overrides in the scene that might make the game objects ignore the imported positions?
There is also a sample where it presents 9 entities, each with a different pivot style to test this exact situation.
Let me know if you find out what might be happening, and if it's something that I might need to address 🙂
So I checked out the samples and I'm running into some issues... mainly that the sample is way smarter than I am and I'm not really sure what's even going on in it...
Though it also looks like you aren't testing with real prefabs.
So I've done my best to make a quick scene that helpfully shows you the issue. StickyTestPivot.zip
In the scene attached as a zip, I set up the LDTK to have entities that are 64x32 [2x1 PPU], and added a ghost tilemap under them so you could see where they should have wound up.
Then in unity I made a very simple prefab that is just a sprite-render.
and finally I assigned the prefabs to the entities then dragged and dropped the LDtk file into the scene.
Ah, my mistake about the pivot example. I must have forgotten about that detail, that they don't actually use prefabs.
But basically, when using prefabs, the prefab's local root space needs to match its pivot point in LDtk. So what you could do, is either change the pivot point of the sprite or make a child game object with a local offset in order to gain that pivot setup for the prefab as well. I noticed in the 2nd image you sent has a rectangle with its own pivot point based around the middle center, which is what's making the rectangle appear as it does in the 3rd image.
It will depend on the situation whether you want to use children or change a sprite's pivot. When I'm faced with the decision, I generally like to use child Gameobjects with a local position to simulate a pivot point in that way.
I have a documentation topic here about it too: The Docs Page
If it still doesn't click, there is a prefab with an offset setup in the Typical2DPlatformer example. (the player prefab)
Let me know if there's any other help I can provide. I'll try checking out the .zip file you sent me when I'm more available 🙂
For the case with your 2x1 prefab, you'd want to make 3 separate prefabs with their own pivot space setup. An ideal implementation for this use-case would be to use prefab variants so that the rectangle can remain the same for all of them, except for the minor local position override.
I got it figured out, though not at all intuitively.
My actual game objects unlike my quick demo were made from many little prefabs in a larger prefab.
Unity doesn't have anyway to set the pivot point on a GameObject So my prefab looked like this:
So the fix was to change it so the first tile was part of the top GameObject so that way it would get the pivot point from it.
Sorry if I'm not understanding correctly, but the first original option can able be correct with a pivot?
I created a setup like your original one, with sprites only as children, and the parent being the rigidbody and collider. I arranged the sprite's local positions so that they can have a pivot relative to their parent.
Also if there was any extra possibility of misunderstanding, make sure the left button in the image below is set to pivot to properly see where the pivot point is on any given GameObject. These buttons are located at the top of the editor.
Let me know if this helped out, or if there was something else you had in mind.
EDIT: Found them they were just Center and global which were throwing me off entirely since I'd never seen nor used that part of the Unity UI before in any of my training videos.
contemplative hum it sounds like there is a way to change pivots on GameObject then...
But I don't seem to have those buttons... which seems to be where my misunderstand is coming from.
They are here in the UI, a little bit to the left, but mainly at the top of the screen. Edit: looks like you found them. Nice.
Also if you don't mind, what is the plugin you use to display gameobject icons in the Object hierarchy? I'm curious 🙂 But I'm glad I was able to help out. If you have any other questions, then send them my way. Or you can contact me on discord if you have any other quick questions. Cammin#1689
I think I got it now... This is one of those times when coming from Godot really got in my way, since in Godot pivots are so easy to work with and as natural as an image editor on everything all this bizarre unity oddness that took 10 youtube videos and 3 guides to wrap my mind around is just bizarre.
That would be Peek: https://assetstore.unity.com/packages/tools/utilities/peek-editor-toolkit-149410
It's a handy addon for someone like me since it helps put more of unities oddly hidden things upfront more like Godot.
Cool. I've seen Peek before, but maybe I should check it out more. I have not exposed myself to Godot much before, but it's slowly been more interesting for me to try out.
I'm not sure how to fix this without doing something weird.
In LDtk I make an Entity the same size as the gameobject/prefab I want to replace it with:
However when LDtkToUnity imports it and places the prefab it doesn't place it to the same alignment, instead it seems to center it on the left corner at the pivot point set in LDtk.
I've tried playing around with the Pivot point options in LDtk, but none of them provide a result that keeps the prefab aligned to the grid.
Centered result:
The only kind of okay way I've found to do it is to use a default 1x1 grid sized entity and center the pivot, but this is kind of unpleasant to work with in LDtk since it means when I have big or even huge entities they still have to be represented by a 1x1 square.