Quick Reply
Search this Thread
Test Subject
Original Poster
#1 Old 27th Feb 2025 at 3:46 PM
Default Question - Postion Relient Interactions
Hello,

I am creating a mod that requires the target Sim to be in bed but not in the sleeping or relaxed position. If the Sim is sleeping, they should first switch to the relaxed position before the interaction can proceed. Once they are in a relaxed position, the interaction should complete successfully.

I have experience creating simple interactions that don’t depend on a Sim’s position, but I haven’t worked with interactions that require a Sim to be in a specific posture while using an object—in this case, a bed. I also need guidance on how to detect, modify, or enforce a Sim’s posture in bed within the interaction logic.

Does anyone have recommendations on how to achieve this? Are there any existing references, resources, or EA scripts I should look at for handling Sim postures in interactions?

Thanks in advance! I’m sure I’ll have so many more questions going forward, lol.
Test Subject
#2 Old 28th Feb 2025 at 3:39 PM
To add a condition when an interaction is available you need to give it a definition with a test method. There you can check for whatever you want. For example the interaction daydream only appears, if the actor is already on the bed.

Code:
public class DayDream : Interaction<Sim, Bed>, ICountsAsIndoorInteraction
	{
		private sealed class Definition : InteractionDefinition<Sim, Bed, DayDream>
		{
			protected override bool Test(Sim a, Bed target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
			{
				if (target.CanBeUsedAsBed)
				{
					return a.Posture.Container == target;
				}
				return false;
			}
		}

If you want to check for the posture you can use

Code:
if a.Posture is RelaxingPosture {}
or
if a.Posture is SleepingPosture {]


For how to enforce a posture, I would look into the classes in the Beds namespace, like DayDream, BedChat or RelaxingPosture, for inspiration. I also haven't done this before but with a quick search I found the Actor.Posture.CurrentStateMachine.RequestState() method, which might be what you need.
Test Subject
Original Poster
#3 Old 8th Mar 2025 at 9:12 PM
Quote: Originally posted by Rites
To add a condition when an interaction is available you need to give it a definition with a test method. There you can check for whatever you want. For example the interaction daydream only appears, if the actor is already on the bed.

Code:
public class DayDream : Interaction<Sim, Bed>, ICountsAsIndoorInteraction
	{
		private sealed class Definition : InteractionDefinition<Sim, Bed, DayDream>
		{
			protected override bool Test(Sim a, Bed target, bool isAutonomous, ref GreyedOutTooltipCallback greyedOutTooltipCallback)
			{
				if (target.CanBeUsedAsBed)
				{
					return a.Posture.Container == target;
				}
				return false;
			}
		}

If you want to check for the posture you can use

Code:
if a.Posture is RelaxingPosture {}
or
if a.Posture is SleepingPosture {]


For how to enforce a posture, I would look into the classes in the Beds namespace, like DayDream, BedChat or RelaxingPosture, for inspiration. I also haven't done this before but with a quick search I found the Actor.Posture.CurrentStateMachine.RequestState() method, which might be what you need.


Thank you! I'm still new to this so it's a bit confusing but you deff helped clarify some things.
Test Subject
#4 Old 8th Mar 2025 at 9:26 PM
Quote: Originally posted by simmerbago
Thank you! I'm still new to this so it's a bit confusing but you deff helped clarify some things.


Happy to help whenever I can
Senior Moderator
staff: senior moderator
#5 Old 9th Mar 2025 at 9:47 PM
You can also set the required posture in an ITUN for the interaction. This is how sitting down interactions work so I imagine it's similar for the relax on bed posture. Maybe have a look at the ITUNs for the EA interactions that work like that
Test Subject
Original Poster
#6 Old 24th Jun 2025 at 11:09 PM
Quote: Originally posted by Rites
Happy to help whenever I can


Hi again! I have an additional question—well, actually, a lot—but I’ll try to keep it relevant to positioning.

Right now, I have my basic interaction working. However, when the interaction happens, the actor and target are supposed to route to a couch and sit beside each other to perform the animations. If the actor is the target, they can route to a couch, dining chair, or rocking chair.

I understand state machines a bit, but I just can't figure out how to route them to another object, have them sit, then start the interaction, and return to sitting afterward.

Do you have any recommendations or mods I should look into to learn more?
Test Subject
#7 Old 28th Jun 2025 at 4:44 PM
I would look into the class for woohoo and how it's handled there in the Run() method since it gets two Sims to lie on the same bed and then lie there again afterwards. Might also be worth a try to look into CuddleSeatedKiss.
But I don't quite understand how your interaction is supposed to play out.
Do you want to initiate it by selecting the other Sim or the object where it's supposed to happen?
And when it's on a chair which of the two Sims is supposed to sit there und what does the other one do?
Test Subject
Original Poster
#8 Old 2nd Jul 2025 at 6:02 AM
Quote: Originally posted by Rites
I would look into the class for woohoo and how it's handled there in the Run() method since it gets two Sims to lie on the same bed and then lie there again afterwards. Might also be worth a try to look into CuddleSeatedKiss.
But I don't quite understand how your interaction is supposed to play out.
Do you want to initiate it by selecting the other Sim or the object where it's supposed to happen?
And when it's on a chair which of the two Sims is supposed to sit there und what does the other one do?


Hi! Thank you so much for the recommendations — I’ll definitely look into the WooHoo class and the Run() method, as well as CuddleSeatedKiss like you suggested.

To clarify what I’m working on: I’m creating a “Look at Baby Pictures” interaction that comes in two versions — a self-interaction and a two-Sim interaction.

For the self-interaction, the Sim would sit on a chair, sofa, or loveseat, and an animation would play.
In the two-Sim version, both Sims would go to a couch or loveseat with two available slots, sit next to each other, and play a shared animation.

Right now, I’m focused on the solo version. The main issue I’m having is getting the Sim to successfully route to and sit on the chosen furniture. Sometimes they walk up to it and then stop, or the game says they can't route there, even when space is clearly available.

I’ve been referencing the NapInChair mod and the GoForJoyride interaction in the game's .dll files, particularly how they handle posture and seating logic, but I’m still running into trouble. Here’s what I’ve got so far...

Code:
public static class CodeSnipits
    {
        /// <summary>
        /// Finds the nearest living chair or couch, routes the Sim to it, and makes them sit using proper posture logic.
        /// </summary>
        public static bool ForceSitWithoutAnimation(Sim sim)
{
    if (sim == null || sim.LotCurrent == null)
        return false;

    GameObject bestSeat = null;
    SitData bestSitData = null;
    float bestDistance = float.MaxValue;

    foreach (GameObject obj in sim.LotCurrent.GetObjects<GameObject>())
    {
        if (!(obj is ChairLiving || obj is Couch))
            continue;

        IHasSeatingGroup group = obj as IHasSeatingGroup;
        if (group == null || group.SeatingGroup == null)
            continue;

        foreach (SitData sitData in group.SeatingGroup.SitDataArray)
        {
            if (sitData.Container != obj)
                continue;

            uint slot = (uint)sitData.ContainmentSlot;
            if (Slots.GetContainedObject(obj.ObjectId, slot) != ObjectGuid.InvalidObjectGuid)
                continue;

            float dist = (obj.Position - sim.Position).LengthSqr();
            if (dist < bestDistance)
            {
                bestSeat = obj;
                bestSitData = sitData;
                bestDistance = dist;
            }
        }
    }

    if (bestSeat == null || bestSitData == null)
        return false;

    // Route to chair
    if (!sim.RouteToSlot(bestSeat, bestSitData.ContainmentSlot))
        return false;

    // Set posture without animation/state machine
    sim.Posture = new SittingPosture(bestSeat, sim, null, bestSitData);
    return true;
}
Test Subject
#9 Old 3rd Jul 2025 at 1:14 PM
Alright, so it's basically two interactions you're working on. For the solo version I really think the best option is the use of an ITUN file like zoe22 said. If it includes the lines
Code:
<PosturePrecondition name="Sitting" value="1">
</PosturePrecondition>

it should automatically find a sittable object, route to it and transition to sitting before starting the main animation. You could copy and edit a different file for all the other parameters.

If you're interested in how that works in detail you can look into ActorSystems.InteractionQueue.ProcessOneInteraction(). This then checks for PosturePreconditions and calls upon a (long) chain of functions to get a fitting object and posture transition.

For how to handle the interaction with two sims on the same couch I still need to do some digging. If I find something helpful, I'll update it.

And as a side note: do you know how to debug your code?
Test Subject
Original Poster
#10 Old 3rd Jul 2025 at 3:12 PM
Quote: Originally posted by Rites
Alright, so it's basically two interactions you're working on. For the solo version I really think the best option is the use of an ITUN file like zoe22 said. If it includes the lines
Code:
<PosturePrecondition name="Sitting" value="1">
</PosturePrecondition>

it should automatically find a sittable object, route to it and transition to sitting before starting the main animation. You could copy and edit a different file for all the other parameters.

If you're interested in how that works in detail you can look into ActorSystems.InteractionQueue.ProcessOneInteraction(). This then checks for PosturePreconditions and calls upon a (long) chain of functions to get a fitting object and posture transition.

For how to handle the interaction with two sims on the same couch I still need to do some digging. If I find something helpful, I'll update it.

And as a side note: do you know how to debug your code?



Thanks so much for the feedback.

Right now, I’m completely new to modding and still trying to figure out how everything fits together. I haven’t worked with ITUN files yet — most of what I’ve done so far is hard-coded in CS, including things like who can use the interaction, relationship checks, etc. I’ve mostly just been pulling things from the game’s DLLs and experimenting to see what works.

For the solo interaction, my current setup does push the Sim to find a chair and sit automatically, similar to how the “Read Newspaper” interaction works — sitting first, then performing the action. I’ve been calling the built-in Sit interaction directly with:

InteractionInstance sit = Sit.Singleton.CreateInstance(bestSeat, ...);

I wasn’t sure if this behavior was posture-related or just how the interaction system works internally, so your explanation about the <PosturePrecondition> tag in ITUN files is really helpful. I’ll definitely look into how ActorSystems.InteractionQueue.ProcessOneInteraction() handles posture preconditions — thanks for pointing that out.

As for the two-Sim couch interaction, I’d love to hear anything you find! That’s something I’d like to get working eventually, too. I think I'm going to conuine with the solo interaction first.

For now, I’m still learning the basics. I know this interaction will require 1. Custom objects, 2. Scripting, 3. Skill making (maybe) and I dont know how to do any of that yet. So maybe I need to go back to foundational stuff. By the way, are there any foundational tutorials or resources you’d recommend for beginners — especially for scripting, ITUNs, or object creation? I’d really appreciate any guidance. I did go to through some tutorials but it can get overwhelming.

Also, for debugging, I’ve been using in-game notifications to track which parts of the code run or fail. Beside that , I do not know how to debug.
Test Subject
#11 Old 3rd Jul 2025 at 6:19 PM
I also come from the coding side of modding and with most of these things I also haven't worked with before, so I'm learning alongside you here

The CreateInstance function together with InteractionInstance.RunInteraction() function should work but I would advice to use as much of the given framework as possible to avoid bugs and exceptions.

For tutorials check out https://modthesims.info/wiki.php?title=Sims_3:Modding. This side organized the most important ones. Alternatively you can use the search function in the tutorial thread.

And last debugging: notifications are also what I use, just wanted to make sure you're aware of them because else you're pretty much working blind. You can also use them to give out parameters and how they change.
Test Subject
Original Poster
#12 Old 5th Jul 2025 at 5:02 PM
Quote: Originally posted by Rites
I also come from the coding side of modding and with most of these things I also haven't worked with before, so I'm learning alongside you here

The CreateInstance function together with InteractionInstance.RunInteraction() function should work but I would advice to use as much of the given framework as possible to avoid bugs and exceptions.

For tutorials check out https://modthesims.info/wiki.php?title=Sims_3:Modding. This side organized the most important ones. Alternatively you can use the search function in the tutorial thread.

And last debugging: notifications are also what I use, just wanted to make sure you're aware of them because else you're pretty much working blind. You can also use them to give out parameters and how they change.


Awesome sauce! Thank you so much. It is certainly a journey, and I wish you luck. I have another question if you don’t mind. I am attempting to push social interactions like Friendly Hug. Do you know where I can find a list of the interaction names? I found some in the DLL, but I can’t locate the hug.
Test Subject
#13 Old Yesterday at 8:35 PM
I don't think there's a complete list of all interactions. Most don't have an itun file. You can find them in the SocialData-Xmls in the GameplayData package (the base game and EPs each have their own Xml). The friendly Hug you're looking for is in SocialData_BaseGame.xml. Interactions that have an Itun aren't part of SocialData and vice versa, at least as far as I could see.
Back to top