Most steel frames typically have integrated hangers, but aluminum frames are usually replaceable. Whether the hanger is removable or not, it doesn't have to be bent very much and it will throw the pulley swing off and cause problems. The easiest way to see if its bent without a tool is to shift to the lowest gear and verify that the pulleys are tracking in-line with the largest cog of the cassette. If the top pulley is further toward the spokes than he cog, and/or the lower pulley is even farther inboard, its most likely the hanger. If that's the case, it totally possible to straighten it "good enough" by eye, just remove the derailleur and use an adjustable crescent wrench to clamp down on the hanger and slowly pull back until the face of the hanger looks parallel to the cassette. Be careful though because as
@60wag said if its aluminum it can be brittle (and those little nuggets aren't cheap!)
If all that looks good then next step is to follow the steps
@Corbet laid out for setting up a derailleur. There is one step however I would add to the beginning of his list which is checking the B screw adjustment. They always seem to come from the factory too far in, and in the case of older bikes at some point somebody has messed with it and it's not in the correct place. To check it's position have the chain in small cog in back with the cable removed. Adjust the B screw in or out to make the guide pulley (top pulley) as close to the cog as possible without actually hitting it. This will help that guide pulley track the chain as close to the cassette as possible. I guess it's also worth noting that there are also compatibility issues between derailleurs and different sized cassettes. Just mentioning in case you have up-sized the cassette at some point (to have a larger low gear) in which case the throw of the current derailleur may not have a compatible swing and causing shifting issues.
Another cause for poor shifting to consider is a worn out chain. Or what's even more common for folks is using a new chain on a worn out cassette. Over time as the pins, and the ID of the chain rollers wear down, and the chain effectively gets longer (chain stretch). Over time the stretched chain wears the drive edge of the teeth of cogs and chain rings. The system works alright until you put on a new chain which doesn't fit with the worn teeth. Its not always obvious, but the first sign of an issue with that is sticky, delayed or ghost shifting in the rear derailleur.
Sorry for the info dump. You might already know all of this, but you mentioned that rear derailleurs give you fits and there are a lot of reasons why following the basic step-by-step setup process might not yield a functioning derailleur. happy to hop on a call if you want more help working through it!