When a villager (v2) tries to go to bed, it can happen that it approaches its claimed bed from the other side of a wall. When this happens, it appears to pathfind through the wall. When it can't reach it, it displays anger particles and wanders for a short time. Sometimes as it wanders it displays green particles as if it discovered the bed again, and sometimes it doesn't, but in either case it can get into a loop trying repeatedly to pathfind through the wall. I have also seen this happen after the villager gets up: It tried to pathfind to its workplace through the wall.
I have attached a test world. To reproduce the problem, simply observe the sole villager for a while.
Related issues
is duplicated by
relates to
Attachments
Comments


Sometimes I see a villager who is "try" to walk towards a bed even though there was a villager sleeping in it's bed and the villager (who tries to walk towards an occupied bed) tries to "push" the sleeping villager. Does this happen to you as well?

@Dylan Zosimo: That may be normal behavior. From what I've seen so far, in certain situations a villager can lose ownership of its bed while it's sleeping. Since the second villager doesn't have a bed yet, it claims the bed and tries to lie down, but the first villager is still in it.

I have Noticed this too. Villagers try to pathfind through walls instead of opening the doors and going inside to sleep. Also if it is raining at night they will not sleep at all. Im on Android Samsung galaxy tab A 2017

What I've found in 1.11.0.9 is that if the door they need to go through is within about 5 or 6 blocks of the straight line path from the villager to its bed or job site block, the villager will find the path through the door. Otherwise, they try to walk through the wall and get frustrated. After getting frustrated 3 times, they relinquish the bed or block and search for a replacement, which usually means they find the same bed or block again and the whole cycle repeats until they happen to wander closer to the door.
@unknown: The issue with sleeping when it's raining should be reported separately. It's caused by the fact that when it's raining, most villagers will go inside the first building they come across, even if it's not where their bed is. Then when it's time for bed they're stuck there because they can't use a door while it's raining. Although that's by design, I'm not sure the consequences for sleeping were noticed, so it might be considered a bug.

Still happening in 1.12. Door will be 5 blocks to the side of where the villagers are standing, trying to go through the wall instead of pathing inside.

I am having the same issue on my Windows 10 Realm. I tried replacing the beds to see if that fixed the issue, but no luck, they keep trying to pathfind though the wall between them and the claimed bed. I've done some testing and noticed that if I break the wall to allow them access to their beds via the path they chose they will pathfind OUT of the structure to get to their work stations come morning.

This issue has been around since the Villager and Pillager update. Villagers try path finding through the wall. Even when enemies such as Zombies and Pillagers are after them. I seen a Villager sacrifice themself because they thought being close to the wall where their bed is on the other side was safe.

I believe faulty pathfinding described here is the root of many relinking issues.
Observed Environments: I have spent a great deal of time working on large villages in both controlled and open environments, as well as both natural and player-created villages. In natural villages, I spend a great deal of time terraforming the space to allow free movement, mainly levelling the space to no more than a 3-block delta and removing any drops greater than one block. In player-built villages, I will bring in one baby villager at a time, link to bed in cell, close off the cell, allow the villager to grow, and set and link a workstation. No villages have rogue POI (not even player beds) or nether portals within ticking distance of any system-defined village border.
In tightly-controlled environments, where villagers are confined to individual "cells" with a bed and workstation, I do not experience linking problems at all. There is almost no pathfinding involved, as the cells are small and do not have partial spaces for villagers to get lost in (like fences or walls). The cells are configured to disallow movement into any partial blocks, including workstations.
Problems arise when villagers are allowed to roam. In both natural and player villages, the villagers will often try to pathfind through obstacles that make no calculable sense. At some points, they appear to prefer not to follow grass path, instead walking up blocks through a building to a solid wall and standing there. It seems as though the block above is not considered in the path calculation, allowing a multi-block elevation over non-preferred blocks to calculate closer than a nearby grass-path-block path straight to the "house". Some of this may be mitigated by changing the path cost of many blocks to a higher value
Collision with other mobs must also be taken into consideration during the pathfinding timeout, probably by resetting the time to POI whenever such collision is detected. Furthermore, when a collision is detected, the affected villager should stop and then recalculate the path after a random time between 1-2 seconds before resetting the path to the POI. Since two villagers are affected in a collision, the recalculation should begin after the random delay so that both villagers do not attempt the same path and form another collision.

The issue also occurs with me and is very irritating I Believe what is causing this is they are trying to get in their bed or use a workstation through corner walls because since it’s one block thick, the villagers believe they can access the beds and workstation through these walls. villagers even go through walls to get to their bed if set correctly

Also affects Nintendo Switch version 1.16.1

I noticed this as well. When ringing a bell they won’t go to their beds.

I think this is the issue I'm running into as well. I lost nearly an entire village due to a disappearing villager bug that I think is related to chuck loading and unloading. So I want to confine my villagers to one chunk and have a few different levels. I started with the idea of one level being for beds, one for a farm, one for workstations. I have a 1 wide staircase running up the wall continuously.
The villagers can wander up and down the stairs fine, but they can't pathfind to their beds or workstations if they are on a different level. They will go directly above or below their target and stare at it through the floor or ceiling. I then tried to get villagers to link to a bed and workstation on the same level but they still wander between levels and get stuck. It's very problematic. The only solution I have left is to make each level self contained with a farmer, a small farm plot, whatever workstation I want, and beds. Access then has to be controlled via iron doors and ladders to confine the villagers to a single level.

Same on 1.16.201

Even when spawning and linking villagers to every bed. The second night they forget the path and try to enter by the other corner of the building surrounded by walls

@unknown: The problem you're describing is common in Minecraft, but unfortunately it isn't a bug; it's an inherent limitation of AI running on a modest computing device. Developers can do some clever tricks to get around this kind of problem, but those tricks don't work in every situation, so you shouldn't depend on them to fix it for you. Fortunately, you almost certainly can fix it yourself, you just need to try some tricks of your own.
The simplest way to fix it is to add a door near where the villagers get stuck. The problem is that they're close to their beds and are looking for a path to go the last little distance, but the path that would succeed takes them too far away. Basically, once they get close to their beds they will only accept paths that keep them close. If they need to go through a door that's 16 blocks away, they won't accept it because it takes them too far from their bed. So by adding a closer door you give them the short path they're looking for. Alternatively, you could just move their beds closer to the existing door.
If adding a door isn't a solution you like, another thing you can try is to prevent them from getting so close to their beds without going through the door. That is, you could block their access to the outside of the building next to where their beds are so that they can't get close to them without going inside. Another way that might work is to change the terrain outside that part of the building to make it 4 or 5 blocks higher or lower than the beds. You could even turn that area into a pond. The idea is just to keep the villagers away from their beds unless they're inside the building.
If you're designing or remodeling a natural village, it will help to make a plan in advance. The best plan I've found is to have a square area of dirt path (formerly grass path) at the center, with scattered job sites around the square, then buildings in a ring around all that. (You could also put the job sites inside the buildings where their beds are.) Put building doors on the side that faces the square, and connect everything using dirt paths. (Many people don't realize that villagers prefer to walk on dirt paths.) If you can, place a bell in the square; it will attract them during the gathering time, which keeps them from wandering out toward the village boundaries where they can have trouble finding their way back. Also, try to keep all the beds and job site blocks within a 64 x 64 area. This will help prevent the village center from moving if you place and/or break beds and job site blocks.
Villagers also prefer to avoid jumping up and down a whole block, so give them stairs or slabs to ease these transitions where paths cross terrain level changes. If you don't, they'll see the lower and upper parts of the path as two different paths and might not choose them as often.

Updated title to distinguish this report from reports of villagers not being able to path around/over beds that are not their own, or just not pathing to POI at all. (MCPE-122682, MCPE-119777).

This problem still occurs in 1.17.0, but there seems to have been some improvement. When I tested the villager with its workstation on the side of the house, it went straight for the door with no hesitation as soon as bedtime came. When I tested it with its workstation directly behind the house, however, it first showed the frustration particles (storm clouds) and looked like it was trying to go through the back wall, but on its second try it went around to the door. So if this behavior is consistently repeatable, I would be satisfied to call this fixed.

The problem still occurs in 1.17.2 on Windows 10, regardless where the workstations are placed. The villagers only find their beds if they accidentally wander toward the door, other than that, they stay stuck behind the wall. World download as proof:
[media]
Edited to add that the carpet next to the bed shouldn't interfere with villager pathfinding, it's just decorative

Still is issue on 1.18

I agree with Vlad 1.18, I just half built a castle (taking a long time) and I was able to move them into the castle as peasants. It's really fun. But when it comes to the 2nd floor, they just stare through the floor at their beds all night long. I also made a quaint chapel and they can't seem to ever get to the job. The bed is near it too. The guy just stands under each object and stares (lectern and bed).

Affects 1.18.31 Hotfix and 1.19.0.28/29 beta & preview

Still affecting 1.19.30

Affects 1.19.60

Affects 1.19.81

Affects 1.20

I'm having a similar issue in Java Edition. I observed them while on peaceful difficulty. I have one house with five beds in it, and only one villager is able to get through the door to its bed.

@unknown: This project ("Minecraft (Bedrock codebase) (MCPE)") cannot be used to report issues experienced in Minecraft: Java Edition. You can use the Projects menu above to select the "Minecraft: Java Edition (MC)" project and search for an issue report there. If you don't find one, you can then create one that will be directed toward the Java developers.

confirmed in update 1.20.72

confirmed in update 1.20.81 but kid villagers know how to open the door and go to the bed during the night time, but when they grow up to adult they can't pathfind to thier bed anymore.
(Bedrock)

This still affects version v1.21.23.

Still affects 1.21.41 on Xbox.

Please reserve comments for providing additional information that might help the devs find and solve the problem. The bug tracker staff normally has no information about when a bug will be fixed or why it's taking so long. We're just volunteers from the community.
Possible workaround:
Something you can do that might help your villagers find the door is to put up a fence or other barrier that prevents them from getting close to the wall near their bed (or workstation). The problem seems to be that they always look for the shortest path that brings them close to where they want to go but don't recognize the wall as a permanent obstruction. If you keep them farther back from the wall, or move their bed or workstation closer to the door, they'll be less likely to get stuck with the wall between them and it.

How about this approach: If a villager has a workstation or a bed they want to reach, they first try to get to the target block directly. If this is not possible (for example, because of a wall), they then look for a door nearby. If a door is found, the villager calculates whether they could get closer to the target block from the door than they could by taking the normal route. If this is possible, they head to the door and then follow the calculated path from there to the target block.

Noted that this issue also happens if the entrance to the building/house has a dirt path block right in front, villagers wont go through the dirt path to access the building/house.
For replicating this just have a building/house with dirt path block in front of the doors or points of entry.
*edit: just rephrasing for better conveing what I have observed. Not stating this an easy fix or the whole issue.

@Kolveman,
I can confirm, but I think this is just a small fraction of the pathfinding bug

Suggesting changes to the game's mechanics isn't forbidden. However, it's seldom helpful because we aren't Minecraft devs and don't know the details about how the engine works, or because we aren't CompSci experts and don't know how to think at the necessary level of detail. Brains are really good at solving problems like pathfinding, brainless computers not so much, and translating what the brain does into steps a computer can follow is hard, real hard. Especially if you have to simultaneously make it work well in a practically infinite variety of terrain and structure configurations, and do all this without degrading performance on the least powerful platform you mean to support.
Consider the suggestion made a short time ago to look for a door. It's too high-level and incomplete. It assumes (1) that the first door detected is reachable from where the villager is, and (2) that the target is reachable from that door. But it won't work if the door is behind a wall: The villager will just get stuck on that wall instead. Obviously, that means you should ignore doors that the villager can't reach directly, but that's the same problem as finding a path to a bed you can't reach directly. Although this suggestion makes perfectly good sense to and can easily be used by a brain, a computer has to have much more detailed instructions.
Finding a path from point A to point B is a classic problem in computer science. In theory, it's very simple to solve: You just have to test every possible path and pick the shortest one. But the brute force method explodes exponentially with each additional step required, so that approach isn't practical. So you have to find an alternate method, and it turns out those are always imperfect in one way or another, which is why the villager gets stuck now. What's needed is a different algorithm that works better in this situation and doesn't work worse in other common situations. But an algorithm like that is hard to find and verify, because Minecraft terrain/world generation is so extremely variable.
In summary, this is not so much a bug as it is a shortcoming of the pathfinding algorithm, and the reason it's taking so long to fix is that every conceivable alternative algorithm is going to have shortcomings of its own, most of them with much worse consequences on performance and/or naturalness of behavior. (Which is important: Villagers may seem not quite as smart as people, but at least they don't usually walk off a cliff or drown in a river.)
And then there are the dirt paths. It's easy to draw the wrong conclusion here because the game mechanics are obscure. Villagers don't avoid dirt paths per se; in fact, it's one of a number of blocks they prefer to walk on, all other things being equal. (This means that when a villager is already on a dirt path, they'll tend to follow it in preference to deviating onto grass etc., and sometimes you can make paths to nudge them toward places they need to go to.) I think the reason they avoid paths in cases like this is that dirt paths are shorter than full size blocks, so a villager calculating the best path sees dirt paths as a step downward from grass, dirt, stone, etc. And upward and downward steps (unless there's a stair) are discouraged by the algorithm, so villagers don't do silly things like trying to climb over blocks or dropping into one block holes that happen to be in their way when they could easily walk around them. The algorithm would probably work better if it only discouraged vertical steps of >1/8 block, but I dunno, maybe checking for that on every single pathfinding step would slow things down too much.
In summary, I think Mojang appreciates that we're trying to help, but without knowing the fine details of all the game mechanics, what we suggest is usually too high-level to implement directly, and besides that they've probably already thought of them and either found they won't work, are impractical because of hardware limitations, cause a different problem, or they're already working to implement them. Or, they've already got a fix but it's part of and dependent on an engineering change, some of which isn't ready for prime time yet. That's something that has happened many times.
Edit: Please don't regard this as an invitation to discuss how to make suggestions better or how you think Mojang needs to change the bug fixing workflow. I posted this to help our Mojira customers understand why fixing bugs sometimes takes a very long time, despite the problem seeming to most people like it's not that difficult. But the bug tracker is not a chat board or other discussion forum; please use the Minecraft Discord for such things.

This is really bad
[media]