I want to have an underlying message in my writing but I really don't want it to come across as annoying or too preachy. Thanks!
No one can really answer that. Because what works for you may not work for me, and that may or may not work for the next one in line. It's personal, and different people need to go about it accordingly. Why? Because it depends on theme, on target audience, on author voice, on character voice, and on setting.
Having said that, let's look at a few tools people use to get it across. First is allegory. Take house elves in Harry Potter, or muggle-borns from the same franchise. This is a clear allegory for racism, classism, elitism, and when you toss in squibs you also get ableism. Notice how none of that was actually said in the books or in the movies?
The there's setting to help tell the tale better. How does this help? Well. Use slavery, whether physical or mental, to talk about freedom.
"But that's not..." Everything about the world going on around the characters, including laws being enforced, is setting. For example, in a world where killing a slave isn't illegal, is a murder mystery all that gripping? Not really, it might be relegated to a Scooby Do type group of kids.
You can also use theme to keep it subtle, or completely hide the intentions of your characters or you as an author. In the Tales of Huckleberry Finn, did you know that what's-his-face didn't care whether the man he'd come to tell his master set him free was freed?
Think about it for a second. A boy is told that a runaway slave is set free, and doesn't have to run any more. And instead of telling him, he pretends to help him run further and further away, coming up with ever-increasingly elaborate plans to keep him safe, making himself the hero. But it's never stated. In fact, most people don't ever realise that's what happened (be honest, can you tell me the name of the boy in question here?). So the theme of physical slavery turns into a theme of mental slavery (he thinks he's still a slave, and continues running from it), showing the the very concept of slavery is all in your mind.
All you have to do is write it into your story, and never expressly state it. Not you, as the author, not the characters, and not the narrator within. Just have it be there and let people figure it out for themselves.
Just as a technical matter, a theme is not a message. Love is a theme. Love sucks is a message.
When you say you want to get across a message in your writing, what you are saying is that you want to change people's minds about some issue: either change what they think about the issue or change how important they think the issue is.
There are two ways you can change people's minds about an issue. One is through argument. The other is through experience. Argument sets out a set of facts, then lays out a conclusion and a set of reasons why the facts lead to the conclusion. This is how you proceed with an essay.
When you set out to change people's minds via experience, you lead them through a set of events and leave them to draw their own conclusions. This can be a far more convincing approach, because people reach the conclusion for themselves. We tend to resist when people try to force a conclusion on us, but we are all in when we reach a conclusion for ourselves. The downside of persuasion by experience is that you run the risk that some readers will draw a different conclusion from the one you intended.
You can do persuasion by experience in both non-fiction and fiction. Journalism and documentaries sometimes persuade by experience by simply telling you real world stories with little or no commentary. (Selection is obviously part of the technique here, and persuasion by experience can be false, just as persuasion by argument can.)
When you do persuasion by experience in fiction, you tell a fictional story that highlights aspects of real experience in the hopes that it will change people's minds about the real world. Dickens and Steinbeck are notable examples of authors who took this route to advocating for social change.
What is striking about the examples of Dickens and Steinbeck is that there is no debate about the issues Dickens tackled and not much about those Steinbeck tacked anymore, and yet their books are still read and admired. They are still read and admired because both provide profound insight into the nature of the human experience in a way that transcends politics or any particular cause.
And that is how you deliver a powerful message in fiction: you write an story about human experience that is simply authentic to life as it is actually lived, without preaching or distorting the truth of lived life in order to push your agenda. Pull that off and people will read you book who have no interest in your cause and who would never take the time to read an essay of even a work of fiction that was a transparent argument for your position.
To convey an underlying message, "X is better than Y", you need to present your "argument" in terms of scenes and characters and have the outcomes for these characters prove the point.
For example, IRL I believe Nordic-style socialism is superior to Western-style free-market capitalism. Now I am well-studied extensively on both, so I can list twenty failures of free market capitalism and twenty huge advantages of Nordic-style socialism.
If I wanted to put that argument into a fantasy novel, I would illustrate the differences with characters trying to pursue their dreams, and failing under free-market capitalism, or doing active harm to succeed. While other characters, under Nordic socialism, do not fail, and succeed without harming anybody, and in truth actually help others to succeed.
I don't have to tell you "X is better than Y", because in the story, Y leads to failure and X leads to success. You don't club people over the head: They may not even figure out this is what the author wanted to say! Because when immersed in a story readers forget there is an author and read the events and outcomes as "what actually happened" (in this story universe) and, unless you stray into reverie-breaking implausibility, it doesn't occur to them this outcome is chosen by you and engineered by you for 250 pages to be how the story turns out: X prevails and kicks Y in the face. And that can happen multiple times in the story, in one form or another, as part of character histories and stories they tell, in the news and politics they hear, in your exposition.
You will have to choose an appropriate story, of course. Detailing the difference in governance between the USA and Norway may not be a discussion to achieve in a story of rival gangs in Chicago. Competing cultural systems could be suited to present day, fantasy or sci fi, however.
This is a topic that will probably vary from author to author according to their style and preferences, but I think some of the best incorporate a theme effectively into a story by approaching it from several different angles throughout the work.
A theme might be a moral, but could also be a general idea that shows up again and again in the world of the story to allow the characters to make some sort of point about the theme as it applies to their world and ours.
For example, take a simple theme like "Individual vs. Society" that's present in a ton of novels today, especially dystopians. The Hunger Games wouldn't be the same if it lacked the theme on any of the many tiers from which it appears: Katniss is initially struggling against the society in which she lives in a passive way by hunting illegally, in an effort to feed her family. Next, she is thrust into the games where she transforms a more literal fight with the immediate members of society, the other tributes around her, into a strategic ploy to topple the greater society controlling them. After winning the games, her enemies are not just Pres. Snow and his Peacekeepers, but the whole philosophy of life in the Capitol. Readers see her disgust at their parties just as much as in the arena. At the climax of the series, Katniss' journey has grown into a direct armed confrontation with those in power in Panem. Without this theme, there would be no story - Katniss would be someone with no loftier purpose than to survive the games and return to life as normal.
More complicated themes like those of religion or dealing with loss might take on an even more multifaceted presence in a story, impacting the characters' lives and environment in diverse ways. The same faith that pulls one of your characters through a period of unimaginable grief might make another horrifically xenophobic and drive away her family, and also determine who their friends are, how they decorate their houses, how the society in which they live is governed, and the settings in which action takes place. In doing so, the work could examine and reveal the good and bad of this philosophy, and take some stance by the end.
Theme is defined in the dictionary as: "an idea that recurs in or pervades a work of art or literature." So, don't just "include" a theme, as in have a character mention it once or have it pop up in some lesson at the very end, but rather bury it in there deep; attach it to some aspects of the story so tightly that there would be no story without it.
You need to integrate this theme into your story.
Take children's stories as an example. They almost always have some morals to teach, but good ones do it very unobtrusively, and you, well, feeling good to be taught morals.
For example, if you look at most Pixar and many Disney animation features, like "Toy story", "Finding Nemo", "Wall-e" and "Zootopia", you can see a very obvious themes, which, if presented alone, would get children and adults only annoyed. But by intertwining these themes with storylines, creators produce a powerful message that resonates with their audience and doesn't cause any pushback.
Certainly, the difficulty of the task depends on what kind of message you want to send. For widely accepted moral principles this is easy. For religious themes this is more difficult, the author would need an extra effort to keep non-religious audience "on board". Or, conversely, like Philip Pullman, author may choose to antagonize religious audience.
If your theme is very controversial and not likely to be received well with any kind of story (ex. benefits of recreational drug use), I would recommend to drop the "theme" part at least partially and instead of creating a message like "This is the right thing", go with toned down message like "This also happens, and not necessarily leads to tragedy".
This is an amazingly broad question and the answer can be "do it well", but I am going to try to tackle it. I think the trick to not coming off as preachy, is to not have characters preach.
Let's say the theme of the book is "anyone who eats red apples dies alone". Never have a character say "don't eat that red apple", just let it happen. Some will eat red apples and die alone, others won't and will have happy lives.
If you do need to tell the reader about it, express it through metaphor. Maybe a worm eats a red apple and dies right away. This tells the reader about your theme, in a direct way, but not by characters preaching the idea.
If you do need characters to talk about it, you should always have a counter point. Have characters that honestly believe the opposite ideas. Don't let those characters be cartoon stupid or evil. Don't let those characters just have straw man arguments to take down. Have them be reasonable individuals that go against the theme.
I'd like to add some thoughts here even though the existing answers are valuable, and one has been chosen, and I'll be incorporating them within my own work. Nonetheless:
(1) Consider your specific goal - the why of why you want to give the message. Do you wish the reader to know up front what the message is, discover the message as they read, or never be aware of the message? Do you wish to persuade the reader, or are you simply hoping to state your case with no concern for the reader's response? Do you wish your readership to be those already in the 'choir' or do you wish to have broad appeal? Do you wish your story to be successful quickly, or are you content if it becomes prescient after you are dead?
I'm a scientist and we are often implored to 'make the science accessible' so that people may understand it more easily. Take opioid abuse, a topic I've begun developing for a story. Heroin and morphine are opioids, and oxycodone is as well. Approximately twenty years ago in the US, regulations were changed so that drug manufacturers could market directly to consumers (commercials on the television; think, Viagra.) Pharmaceutical reps go to the doctors and give them free samples of all sorts of drugs (acid reduction, skin medication, you name it, pain relievers.) The US is litigious, we'll sue easily. Doctors, enough of them, truly want their patients to be 'well.' Feel better.
Within this mix it is easy to understand how corporate interests ('Big Pharma') can maneuver to a position of greater profit. This comes at a cost of more patients on opioids, and when their prescription runs out or they abuse and take too much or the doctor ends his practice or or or... They can get a similar compound on the street, which is unregulated, like dirty heroin.
Addiction is a demon.
So right there are a lot of ideas, and I can write a story about a person going through this, maybe a roofer who fell and broke their back, becomes addicted, can't get work, and things spiral out of control.
Plenty of celebrities have been found dead from heroin overdose, and some may have started with a prescription painkiller.
(2) Imagine it from the reader's perspective. Perhaps the reader is taking oxycodone. Becoming addicted. If they pick up this story, should they know at the outset that it will be a damning commentary on the events that led to the current opioid crisis in the US? They might not buy it, or they might, if they know up front.
I've read plenty of books though, where halfway through I figure out that the author is really saying something else and become angry that the author is trying to tell me what to think. I throw the book across the room or throw it clean away.
Dickens is an excellent example of cleanly executed straight-up stories about social ills, +1 for that. I wonder if the stories were successful in their time?
(3) You can't please everybody. Approximately half of the IRL people I discuss my book with tell me they won't read it precisely because it sounds like it will be preachy. I'd personally rather tell the science (of, for example, addiction) (and history, and capitalism) in the form of a story: for those who have no idea but might want to know what opioids are, and the reason people think they want it is because of the marketing campaigns, and by the way here are the side effects you don't hear about, and here are the numbers on the deaths and effects to the economy. I could do this in a spread sheet, instead, but I guarantee no one will read that.
So if it's clear up front that this is the intent, to make the science 'accessible,' then sure, a can of worms might open up, but my motivation is served and no one who would be put off has to buy it to begin with.
My answer: Determine your goals for writing what you're writing. Ask yourself which readers you are trying to reach. What would those people like to see, in your story? A direct message, stated explicitly? Or something more subtle that might be lost and even misunderstood?
Don't lecture; Make it natural, not forced; Teach Characters lessons, not the audience
An example of lecturing:
In the middle of a desperate mission to save the Resistance, Rose takes the time to deliver a little speech to Finn about the seedy side of the opulent city they're visiting. The speech has no bearing on their mission. It does nothing to move the mission forward. It's jarring and came off as 'preachy' to me. Don't have characters stop what they're doing to deliver paragraphs of message. That doesn't really happen in natural conversation.
An example of forced character growth:
In TLJ, again, Po has a character arc where he learns to be less hotheaded. The trouble is, the movie clearly shows us that Po is learning this lesson through dialog but the actions that lead him down this path don't really seem to correlate with the lessons hes "learning".
Po's initial action is ignoring Leia to take out the Dreadnought. He succeeds. Destroying billions of credits of material, time, and killing over 200,000 trained enemy combatants at the cost of several bombers. This can only be a good thing, but he's reprimanded by Leia for being hotheaded, starting his character arc. The next thing is his mutiny, which again, seems perfectly reasonable since the only reason Holdo could have to withhold a plan is if she didn't have one, or it was too awful to share. Finally, showing us that Po has completed his arc, Po calls off the speeder attack to save the speeder pilots' lives. But this is unreasonable. They will all die if they can't stop the Space Battering Ram.
You can tell the writers wanted Po to learn a lesson (and by extension, the audience) and have an arc, but they did so in a way that didn't really make much sense (to me, at least) and in a way that required contrivances like Holdo's silence.
A Good Example Spiderman 1 (Toby Mcguire)
At the cage fight, Peter is shorted the money he was promised for winning. A short time later, he sees the guy who shorted him getting robbed and decides not to intervene as a way of getting payback. This is a perfectly reasonable reaction. But, (spoilers, I guess?) it leads to the robber killing Uncle Ben. This is also a perfectly reasonable extension of events. The message communicated is clear: "Take responsibility and do what's right, even if they person you're helping is a jerk".
That message, or theme, is something Peter learns, but as we see the story unfold, we learn that message as well.
If you don't agree with my assessment of TLJ, please just take it as the way I perceived the movie.
Which brings me to a final point, know your audience. If you try to convey a message to people that "Murder is ok", it's probably not going to resonate with average people, regardless of how that message is delivered, and it'll probably come off as preachy, but if you're selling to serial killers on death row, they might not think so.