I’ve created a placing function for held objects so that they can be put down on surfaces, if they have the right surface normal orientation. The broad strokes are:
Pick up object using UPhysicsHandle
Point camera at a surface with a surface normal of 0,0,1
Click to place the object
Line trace and break hit result
Get “Normal” and “Location” from hit result
Check if Normal is equal to 0,0,1
Call Set Object Location and Rotation
Plug in Location from Hit Result, leave Rotation blank (for now) and
Call Release Component on the UPhysicsHandle Component of my First Person Character
This seems to be working well so far, but I am predicting issues if the player ever finds an even surface that is on top of a small, interactible actor, on which the held object should not be placable. Additionally, even if the surface should be accepting of placeable objects, what if the object, once put down, starts colliding with adjacent objects?
My question is: How do I check for these eventualities and prevent them from producing potential glitching?
To make sure it doesnt spawn on an interactible actor you can take the other actor from the hit result and check if it is an interactible and prevent the object from spawning. Also if you want to avoid it colliding with other objects, I guess you could box trace just above the hit location (make sure the box does not collide with the floor) to check if there are any objects colliding with the box, meaning that there is not enough space. Make sure to adjust the size of the box to the minimum space the object you want to place will require to spawn.
I remember having a similar problem, I dont think it is possible if the actor does not have a standard collision. But if all your objects use the same collision type, maybe get the extend of it? Or if not, you could add a variable to each object and manually set it to the desired box extent for each object?
Have the base interactable actor class (or anything else that should not accept an item) carry a PlaceNoItemsHere tag, and query hit components for tags. Or the other way round, tag the shelves instead - whatever seems more natural / convenient.
Additionally, even if the surface should be accepting of placeable objects, what if the object, once put down, starts colliding with adjacent objects?
Either box/sphere trace to find large enough empty space or…
…when the trace hits the surface; you know the transform of the item you’re placing:
Alternatively, set the component you’re plopping down to overlap all, and query for overlaps:
If the array does not return anything conflicting, place the item and revert to the original collision settings. Ideally, you’d have channels / object types set up for those operations. Maybe even a full profile to make it easier in the long run.