How to have the Player place GameObjects in scene at runtime?

Long story short, what are the concepts to let the player place GameObjects in the scene in game.

e.g. Player has built a fence section and I would like him to place it in the scene wherever they please.

I was thinking of RayCasting and then having code to change the position and rotation of the Object in question to that of the point where the ray contacts the terrain or similar. Is this the correct way to go about it? Are there other methods I should use? Is this even feasible in Unity?

My goal is for extreme customization to the environment that would mean letting the player place GameObjects wherever they deem fit.

GameObject.Instantiate() will let you instantiate a new instance of an existing object or prefab, with potential paramaters of a position and rotation. From the sounds of it, this is what you’re after; as you suggested, the best way to go about it would be to raycast to find their selected location and then instantiate the selected object.

From there, (depending on what you wanted to do with it) you could allow the rotation/further translation of the newly instantiated object.

If you’re concerned about the performance impact of instantiating objects, you could then look at pooling your objects, but as far as the functionality you’re after you should be ok with the above.

For anyone still seeking answers to this question, check out this video. It helped me a lot.

Player placing objects at mouse cursor