How can I create an object from an object variable?

How do I…

I’m trying to make a game in which you can decorate a house by dragging items from a menu to put them into the grid area. I want to have it so you drag a “ghost” of an item out of the menu, and when you release your mouse it places the real item where the ghost just was, and the ghost goes back to the menu. I’ve been trying to use the “create object from name” command with object variables to do this, but it only seems to create the first object in the group, no matter which one was dragged. Is there any way to make it select the variable within the object being interacted with? Is there a better way to do this?

I can’t crop it small enough to just have the one event, so I included the whole block of them. Sorry!

It doesn’t look like you’re putting the “ghost object” back into the menu after creating the “real” one. Also, could you show us the object group, and the itemName definition of one of the ghost objects (one that is different from the first in the group preferably)? The name needs to match exactly.

For better organization, I would recommend separating the ghost objects from the real ones. It looks like they are all in the same group which could make things confusing, as you want them to behave differently. I would make a totally separate GhostObject which only exists in the menu, with a different animation for each type of object that it can create. Then you can get the object name using GhostObject.Animation::Name() (again just make sure they match)

As always I have to nitpick your events because there are a lot of duplicate conditions here. Also I’m not sure why you are using a scene variable for the original position (tempX/Y) that is being set every time. When the menu is initialized, you could store this information for each object in the menu as object variables. Something like DraggableObject.OriginalX (I usually just do oX and oY for short). So overall I would reorganize like this:

Draggable is being dragged
__________________________________________________________
   |the X position of Draggable is < 3087  |     change variable inMenu = false
   |                                       |     change size to 300x300
   |                                       |     snap to grid
   |__________________________________________________________
   |the X position of Draggable is >= 3087 |     change variable inMenu = true
   |                                       |     change size to (normal size)
__________________________________________________________

Draggable was just dropped
__________________________________________________________
   |the variable inMenu is false           | Among RealObjects, create Draggable.itemName at Draggable.X(), Draggable.Y()
   |__________________________________________________________
   | <empty>                               |  Change position to Draggable.oX, Draggable.oY

At the end I returned the position of the dragged object with no extra condition since I assume it should go back into the menu regardless.