Forum rules - please read before posting.

Remember animator script - Remember controller question

edited August 2024 in Technical Q&A

Hello everyone, this is my first post on the forums!

I have a question. I'm currently working on a project where we need to save the animation controller set in the Animator for various objects. I've already attached the RememberAnimator component to them, and I know the documentation suggests that the correct way to handle this is by setting the script's bool to true and moving the controllers to a "Resources" folder. However, I don't want to move hundreds of controllers to a new folder, as it would change the current workflow with animation controllers and could risk breaking some other references.

Is there any other way to make the RememberAnimator script save the controller without using the "Resources" folder? Maybe by creating a custom script where the references are set manually?

Thanks for any answers!

Comments

  • Welcome to the community, @JesusBando.

    If you import Unity's Addressables package, you can then check Save asset references with Addressables? in the Settings Manager.

    This will cause AC to rely on the Addressable system to retrieve assets when loading. Preparing the Animator Controller asset would then be a case of giving it a unique filename, and marking it as Addressable with a key that matches this name.

    Details on this topic can be found in the Manual's "Saving asset references" chapter.

    Alternatively, a custom script is certainly an option as well. AC supports the addition of custom Remember scripts - see this tutorial. If you had another means to record/update an Animator's assigned controller asset, you could implement it in such a script, attach it to the Animator, and uncheck AC's own option to do so.

    Because Remember Animator would still be applying its own data, however, you'd need to ensure that your own script would get applied first. This can be done by overriding its LoadOrder property with a negative value.

  • edited September 2024

    Im trying to do it via the addressable method, i installed the package set the check-box in the AC settings and i added the "AddressableIsPresent" preprocessor in the Define symbols of the player settings,also i set the controllers as adressables and symplyfied their addresabble names, after that should i change anything in the remember animator script? there is a lot or commented sections regarding addressables. @ChrisIceBox

  • What's your AC version? With the current release, adding "AddressableIsPresent" is not necessary.

    No script changes should be necessary - what you've described should be enough. What is the result now of saving and loading?

  • We are currently on v1.74.2 testing with the described setup is not saving the animator controller change during runtime, both the original and the new controller are set as adressabbles.

  • Does this occur in the Editor, or just builds, do any related messages appear in the Console when either saving or loading, and have you built your Addressables?

    Use the Save-game File Manager, accessed from the Settings Manager, to view the saved data for this particular scene. Under the "Remember data" section, look for the object with the matching Constant ID, which should display (in raw data form) the contents of Remember Animator.

    Does it list the name of the correct Animator Controller asset? You're welcome to share screenshots of this window / a copy of the "Copy as Json" buffer if you want another set of eyes on it.

  • edited September 2024

    Also adding the "AddressableIsPresent" in the player settings make a bunch of errors appear on the console, i think previously i set it up incorrectly, now that it is correctly written i have a bunch of errors. image: https://imgur.com/a/vl0e97e

  • Which version of Unity are you using, and what version of the Addressables package have you installed? The errors suggest AC now recognises that Addressables should be present, but the package itself is not what it expects.

  • Im on unity 2022.3.26f1, and the addressables package version is 1.21.21
    image: https://imgur.com/a/PzfyyHG

  • I cannot recreate such an issue with the same AC/Unity/Addressable versions.

    Though: are you using an Assembly Definition file? That would need to be updated with the new assemblies now being used.

  • Yes!, i think that might be it, which definitions should i add? all of the addressables ones?

  • I added these two,"Unity.Addressables.Editor", "Unity.Adressables", to the Assembly definitions, but the problem persists the same errors appear on the console, i dont know what may be happening :'(
    here are some images of my setup: https://imgur.com/a/NPKHx4M
    @ChrisIceBox

  • Look for the "Unity.ResourceManager" definition - that'll need to be added as well.

  • edited September 2024

    just try this some more errors appeared in the console
    https://imgur.com/a/SVK3o4s
    I just forgot to aply the changes on the definitions, but it worked!, thank you very much @ChrisIceBox

  • @ChrisIceBox i found one problem, everything is set up correctly and now im able to reference the controllers correctly setting them up as addressables, but now the remember transform componen do not seem to be working each time i load the transform data that was previously loaded correctly does not work, that is for position rotation and parent changes, if i set the save asset references with addressables checkbox back to cero, so it does not use it, it works normally, but if i tick it, it stops working, and this errors appear
    image: https://imgur.com/a/4U0dFCW

  • The Save asset references with Addressables? option alters the format of save-game data - once you alter its value, previously-recorded save game files cannot be loaded.

    Do your Remember Transform components have Save scene presence? checked? They will need to be updated to work with the Save asset references with Addressables? option if so.

    If you wanted the affects of the Save asset references with Addressables? option to only be felt by Remember Animator, you can uncheck it, open up the RememberAnimator script, and replaces the two instances of:

    if (KickStarter.settingsManager.saveAssetReferencesWithAddressables)
    

    with:

    if (true)
    
  • edited September 2024

    @ChrisIceBox i alredy unchecked and did the changes and it didnt worked here is the only part theat i found matched the lines you mentioned in the script
    "public override void LoadData (string stringData)
    {
    AnimatorData data = Serializer.LoadScriptData (stringData);
    if (data == null)
    {
    loadedData = false;
    return;
    }
    SavePrevented = data.savePrevented; if (savePrevented) return;

            loadedData = true;
    
            if (!string.IsNullOrEmpty (data.controllerID) && Animator && saveController)
            {
                #if AddressableIsPresent
    
                if (true) // changed from KickStarter.settingsManager.saveAssetReferencesWithAddressables
                {
                    StartCoroutine (LoadDataFromAddressable (data));
                    return;
                }
                #endif
    
                RuntimeAnimatorController runtimeAnimatorController = AssetLoader.RetrieveAsset (Animator.runtimeAnimatorController, data.controllerID);
                if (runtimeAnimatorController)
                {
                    _animator.runtimeAnimatorController = runtimeAnimatorController;
                }
            }
    
            StringToParameterValues (Animator.parameters, data.parameterData);
            StringToLayerWeights (data.layerWeightData);
            StringToStates (data.stateData);
        }"
    

    so to be more clear, when using addressables the remember transform stops working, stops recording the transform, rotation, and changes in the father object, im not using the remember transform to save the scene precence, so that is unchecked.

  • i alredy unchecked and did the changes and it didnt worked here is the only part theat i found matched the lines you mentioned in the script

    That's the correct line change. Don't remove the AddressableIsPresent define symbol.

    Looks like you also need to replace:

    animatorData.controllerID = AssetLoader.GetAssetInstanceID (Animator.runtimeAnimatorController);
    

    with:

    animatorData.controllerID = string.Empty;
    if (Animator.runtimeAnimatorController)
    {
        string _name = Animator.runtimeAnimatorController.name;
        _name = _name.Replace (" (Instance)", string.Empty);
        animatorData.controllerID = _name;
    }
    
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.