Ok so this may seem like an odd question but I’m struggling with finding an easy answer. I have a scenario in which I am constantly attaching actors to other actors in gameplay. It’s a jigsaw puzzle and the pieces snap to each other. Technically I am actually spawning a new “snapgroup” actor and attaching the pieces to that actor so that they then move as a unit. I’m using the AttachActorToActor node. My problem comes up when I need to save the game. I am saving the location info for all the pieces as well as for the snapgroup actors each time a piece or a group moves. For the most part this works fine but when testing for the piece locations after they’ve been grouped I believe it’s giving me the local space instead of world space because when loading a saved game all the pieces are basically where they should be but some of them are slightly off the mark when they’ve been grouped. Oddly though it’s inconsistent. Sometimes the pieces seem to be where they should be and sometimes they are off by a tiny amount.
Anyway is there a way for me to get a world space location for an actor even if it’s attached to another actor?
You can always get correct world location of an actor by calling *GetActorLocation (or GetWorldLocation *for components). And you can transform between local and world space like so:
The tooltips explain which way is which. Also works for rotation, direction and matrices.
On the other hand, this would indicate that something else is going on here. Could demonstrate the inconsistency you’re referring to? How are you snapping them together?
Thanks for responding. Yeah my scripts are complex enough it’s certainly possible something else is happening. Everything seems to work fine though except when saving/loading and using the stored location info to place the pieces when they have been grouped.
This is the piece of my script where I attempt to get the world space location of the pieces within a group and store that in the struct for future loading. I was using the getActorLocation but just now I attempted the GetWorldLocation but it didn’t seem to make a difference.
Also don’t know if it makes a difference but when I use the AttachActorToActor for grouping purposes I have everything set to “Keep World” Because I have a difference set of scripts that position the puzzle piece exactly where it needs to snap to the specific edge it snaps to.
Also I’m not really clear on the mechanics of the AttachActorToActor. When you use that node does the one actor actually become a scenecomponent of the other or is there a difference parenting mechanic for that node?
Actually I think I just figured it out. I dug through my other snap position scripts for when I do my grouping. I wasn’t consistent enough. I made it a point to always group to the dragged actor for consistency but then just now I noticed that my snap position script was moving the overlapped actor into place instead of the dragged actor and THAT data wasn’t being saved. So I now think I just need to go back and change the snap position scripts to move the dragged group instead of the overlapped group (or save the overlapped group move data as well but that sounds less efficient.)
Anyway thanks for trying to help.
Do tell if you figure it out.
Yup. It was what I thought it was. I just converted all my puzzle piece snap position scripts to move the dragged piece into position instead of the overlapped one (since that is the group/pieces that get updated on piece drop) and it works fine now.