Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Quick Reply
Search this Thread
Field Researcher
Original Poster
#1 Old 2nd Apr 2022 at 2:00 PM Last edited by lizcandor : 10th Apr 2022 at 9:36 PM.
Default Mannequin clone turns to gray ball when live dragged or reloaded
I have an object (but probably scripting-related) question - I've made an object cloned from the ITF clothes mannequin that can take on a sim's appearance, and made it moveable in build/buy mode and by live dragging. But when I live drag it, it loses the pose and appearance of the sim it's been set to mimic and reverts to its original form of a small gray ball instead; this doesn't happen when it's moved in build/buy mode. Has anyone seen/solved this before?

Edit: Oh, it looks like it also turns into a gray ball when I reload a save where one was placed.

Edit: Using SetModel to set the model of the mimic as a copy of the mesh of the mimicry target (CaptureMeshForSculpture) lets the mimic keep its shape when dragged, but it turns totally black and is put in the wrong pose. So I guess that means the problem is the object needs a model set in-game if it doesn't have a MODL resource?

Edit: I seem to have fixed the live dragging issue by removing the HandToolAllowPlacement, HandToolAllowPlacementInSlot, and HandToolAllowDragDrop methods I'd added to the objects class while trying to figure out how to make it moveable, but I'm not sure why that worked.

Edit: Seems like the reason the appearance doesn't reload properly is because the mimic's outfit field (stores a SimOutfit object) is lost when the world is quit and reloaded. But the other fields are fine, so I'm not sure what about the outfit field is making it not reload?
Advertisement
Virtual gardener
staff: administrator
#2 Old 4th Apr 2022 at 2:33 PM
Quote: Originally posted by lizcandor
I have an object (but probably scripting-related) question - I've made an object cloned from the ITF clothes mannequin that can take on a sim's appearance, and made it moveable in build/buy mode and by live dragging. But when I live drag it, it loses the pose and appearance of the sim it's been set to mimic and reverts to its original form of a small gray ball instead; this doesn't happen when it's moved in build/buy mode. Has anyone seen/solved this before?

Edit: Oh, it looks like it also turns into a gray ball when I reload a save where one was placed.

Edit: Using SetModel to set the model of the mimic as a copy of the mesh of the mimicry target (CaptureMeshForSculpture) lets the mimic keep its shape when dragged, but it turns totally black and is put in the wrong pose. So I guess that means the problem is the object needs a model set in-game if it doesn't have a MODL resource?

Edit: I seem to have fixed the live dragging issue by removing the HandToolAllowPlacement, HandToolAllowPlacementInSlot, and HandToolAllowDragDrop methods I'd added to the objects class while trying to figure out how to make it moveable, but I'm not sure why that worked.

Edit: Seems like the reason the appearance doesn't reload properly is because the mimic's outfit field (stores a SimOutfit object) is lost when the world is quit and reloaded. But the other fields are fine, so I'm not sure what about the outfit field is making it not reload?


I could be completely wrong here, but i'm guessing the reason that it does this, is due to the fact that it's a very "lite" version of a sim. So, whenever the mannequin is grabbed, the pose data and the rig gets lost. whereas with the live dragging, it merely changes the world position coordinations on an object.

Regarding the outfit thingy, it seems that you might want to keep it as persisted data and call the "CreateMannequin()" whenever you're reloading
Field Researcher
Original Poster
#3 Old 9th Apr 2022 at 3:00 PM Last edited by lizcandor : 10th Apr 2022 at 1:57 PM.
The outfit just won't seem to persist :/ The outfit resource key field does, but the outfit field doesn't, and trying to generate the outfit from the key with OutfitUtils.TryGenerateSimOutfit returns false. Maybe there's something special about how outfits get persisted? I'm trying to imitate the way that SimDescription or ClothingPedestal stores outfits now but it's kind of a mess to follow, hoping for better results though.

Edit: I tried using Consort's solution to what sounds like the same problem in this thread and have turned my previous problem into a new, different problem - refreshing the mimic's appearance now turns it into some kind of weird thing that doesn't even look like a sim anymore. But this weird effect is persisted across loads so I'm considering it progress.

Edit: A slight adjustment to Consort's solution (I'm guessing because Consort was applying stored CASParts to an actual sim, instead of to an object that didn't have a rig yet) fixed it:
Code:
SimBuilder simBuilder = new SimBuilder();
            OutfitUtils.SetOutfit(simBuilder, mBaseOutfit, null);
            simBuilder.UseCompression = true;
            simBuilder.Age = mAgeGenderSpecies;
            OutfitUtils.SetAutomaticModifiers(simBuilder);
            foreach (CASPart part in mCASParts)
            {
                simBuilder.AddPart(part);
            }
            ResourceKey resKey = simBuilder.CacheOutfit($"RebuiltMannequin_{simBuilder.SkinToneIndex}_{simBuilder.SkinToneIndex}");
            CASUtils.SetOutfitInGameObject(resKey, base.Proxy.ObjectId);
mBaseOutfit is an empty outfit by the time this code is called so that line might not actually be needed; mAgeGenderSpecies is the mimicry target's CASAgeGenderFlags, stored when their appearance is first copied; and mCASParts is an array of CASParts copied from the originally mimicked outfit as in Consort's example. Then you have to add some extra stuff to copy over the skintone, morphs, facial blends, and color presets, but it's pretty straightforward!

Edit: Final edit - the last problem to solve was that the mimic also lost its appearance when added to and then taken out of an inventory, and the solution to that was to call the method that re-applies the appearance from the object's OnHandToolMovement() override.
Virtual gardener
staff: administrator
#4 Old 10th Apr 2022 at 4:46 PM
Good to hear you've fixed it! Outfits are quite hard to work on code-wise (and simply confusing sometimes lol)
Field Researcher
Original Poster
#5 Old 10th Apr 2022 at 5:03 PM Last edited by lizcandor : 10th Apr 2022 at 11:36 PM.
Agreed, main thing I've learned here is outfits are potentially super versatile but also just the biggest pain XD

Edit: Ahhh there's still one more case I haven't solved, mimic loses its appearance when the level of detail it's rendered with changes (or I assume that's what's happening when I zoom out to neighborhood view and then zoom back in). Back into the code I go.

Edit: Seems like the solution to *this* is that the mimic needs to be a sim ("Sim" checked in the OBJK), but the reason I'd unchecked that to begin with is it can't be moved in build mode or by live dragging if it's a sim. Hmm.
Field Researcher
Original Poster
#6 Old 30th Apr 2022 at 12:08 AM Last edited by lizcandor : 30th Apr 2022 at 8:42 PM.
After fighting with this for multiple weekends I've finally made progress! And without making the mimic into a sim [edit: lol nope I gave up], it's still just a regular moveable object. I added a callback that's triggered when map view is toggled on or off, by putting this line in the mimic's OnStartup method:
Code:
CameraController.OnCameraMapViewEnabledCallback += OnCameraMapViewDisabledCallback
And had OnCameraMapViewDisabledCallback do this:
Code:
public void OnCameraMapViewDisabledCallback(bool enabled)
{
      if (!enabled)
      {
            Simulator.AddObject(new OneShotFunctionTask(new Function(RefreshPoseOnToggleView)));
      }
}
And then RefreshPoseOnToggleView fixes the mimic's appearance like this:
Code:
public void RefreshPoseOnToggleView()
{
     while(LotCurrent.mDisplayLevelInfo.mCurrent>(int)1)
     {
          Simulator.Sleep(1u);
     }
     RefreshPose();
}
If I'm understanding Lyralei's code snippet correctly, this makes it so the mimic gets refreshed as soon as the game is ready to display it and not before; my first solution, just making OnCameraMapViewDisabledCallback add an alarm that would call RefreshPoseOnToggleView when it fired after some number of seconds, had some timing issues that this approach doesn't.

This works fine when the mimic is on the active lot, but if it's anywhere else - the world lot, a community lot, a residential lot other than the active lot - LotCurrent.mDisplayLevelInfo.mCurrent seems to always be 0 (on the active lot it's 5 in map view and 0 when zoomed in), so RefreshPoseOnToggleView tries to refresh the mimic's appearance too early and it doesn't work. Does anyone have any idea why this is?

Edit: Finally I figured out mDisplayLevelInfo is about what floor of the lot is displayed, not the lot's level of detail I was able to trigger the refresh based on the camera's zoom level instead, and that worked better, but still doesn't cover every case. What I need is a way to detect every time the zoom changes significantly or the camera moves enough to change which lot is in focus, I think?

Edit: I went back to making the mimic a sim in its OBJK and tried to investigate the other major problem with that approach (besides being immovable), that it sometimes disappears on world load. It seems like what actually happens is that it reloads fine if it was placed on the world lot, but not any other lot?

Edit: Solution to *this* seems to have been to make the mimic implement ICanExistNotOnLot, because I guess LotManager.CleanupObjectsNotOnLot was destroying it for some reason? ICanExistNotOnLot prevents that. I don't understand and it's not the solution I want since the mimic is still not movable, but I guess it works for now.
Back to top