can i raycast from a parent to its child and get hit info

if (Physics.Raycast(ray, out hit))
{
//Replace the wall with door
Instantiate(doorPrefab, hit.collider.transform.position, hit.collider.transform.rotation);
Destroy(hit.collider.gameObject);
}

this is the problem : I have two rooms spawning side by side and i want a door between them so i raycast from say room1 to room2 and destroy the wall and place a door there but it ignores the walls of room1 and places door in room2 which i don’t want i want door to be in room1 i thought raycast maybe ignores it’s child so i did this:

private void Awake()
{
    Transform[] children = gameObject.GetComponentsInChildren<Transform>();
    foreach (var child in children)
    {
        child.parent = null;
    }
}

and it doesn’t work can anybody help

I appreciate the information and advice you have shared. I will try to figure it out for more.
My Waffle House

does the ray start inside the wall? it does not register a hit if it inside the collider you want.

are the walls triggers? it does not hit colliders with trigger enabled.

can’t see what your ray is and where it starts but it should start in the middle of the room and have a layermask of only the walls.