Search Unity

cinemachine freelook prefabs seem to become corrupted

Discussion in 'Cinemachine' started by mradfo21, May 24, 2018.

  1. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    Cinemachine freelook cameras seem to have alot of trouble keeping their settings when saved as prefabs. I cant exactly figure out what corrupts their data. But the Top Rig, Middle Rig, Bottom Rig settings seem to get corrupted and reset every now and then. I can tell when this happens too as the arrow next to them disappears

    upload_2018-5-24_11-37-31.png

    when I select one of the corrupted rigs
    upload_2018-5-24_11-38-1.png

    i see this appear in the object heirarchy

    upload_2018-5-24_11-38-19.png


    the ONLY way to keep them for sure is to save via unity collaborate and constantly revert them after working in the project ... man.. what a nightmare
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    oh really ?!
    what version of Unity?
     
  3. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    2018.1.0f1
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    trying to repro... can't seem to do it. Any thoughts on what kind of things you're doing in the editor that might make it happen?
     
  5. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    hehe its slowly corrupting them more and more

    upload_2018-5-24_13-32-54.png

    so i'm not sure. I do have some editor scripts that are running update methods and I do have an

    [InitializeOnLoad]

    that automagically spawns some gameobjects and prefabs into the scenes (but not the cameras).

    I'm not sure but i'll keep testing and see if i can find a pattern
     
  6. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    luckily collaborate's revert is saving me
    upload_2018-5-24_13-36-0.png
     
  7. Feriluce

    Feriluce

    Joined:
    Nov 28, 2013
    Posts:
    5
    I have a very similar, if not the same, problem. I have created a prefab with cinemachinefreelook on it, and it seems that whenever I try to change settings on that prefab, it spawns those 3 rigs in the scene, tries to parent them to the prefab, which fails, and then throws this nullreferenceException.

    Error.png
     
  8. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    hurrah! im not crazy!
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    I really can't repro this!
    Can you tell me which version of Unity, which version of CM, and what exactly are the steps to reproduce?
    I've tried changing all sorts of settings but it refuses to misbehave.
     
  10. Feriluce

    Feriluce

    Joined:
    Nov 28, 2013
    Posts:
    5
    I'm using unity 2018.1.0 and Cinemachine 2.1.13, but I just tried to reproduce it myself, and now it doesn't happen for me either.
    It seems like the problem was in creating the prefab though. When I tried creating new prefabs this time, the 3 child rigs were created underneath the prefab. That didn't happen with the prefab that was broken. That one was just a single object, which I assume is why it kept trying to create the missing rigs.
     
  11. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    Ok here's how I think you repro this. Make a cinemachine prefab out of a free look. Instantiate it at runtime. Make changes to it. Drag that to make a new prefab on disc. Then drag the camera ontop of the original prefab to replace its settings.

    Now you'll start to see TopRig, MiddleRig, and BottomRig appear in the heirarchy of the game. This means your F***ED. Cinemachine is now destroying your cameras.

    Restart Unity and you'll be greeted with this:

    upload_2018-6-22_17-7-1.png

    Not having the arrows next to your camera is BAD NEWS.

    When you run the game cinemachine will make have erased all your rig settings and there's no way to get them back outside of version control.


    Now this could ALLLLL be avoided if you could actually copy the rig settings during runtime and paste them onto the prefab on disc like every other object in unity. I know you'd mentioned this was working but it does not sadly.
     
  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Not sure exactly what you mean by that last step.
    After making the second prefab, if I drop my FreeLook from the hierarchy onto the prefab, all is fine, the settings get copied. If I try to drag the second prefab onto the first prefab, I get this:

    upload_2018-6-24_8-13-13.png

    If I click Yes, then click on the profab, then the Top, Middle, and Bottom rigs from the prefab get moved to the hierarchy, and the prefab is broken.

    Is that consistent with what you're seeing?


    If I do this on the FreeLook in the hierarchy:
    upload_2018-6-24_8-27-47.png

    Then this on the FreeLook in the prefab:
    upload_2018-6-24_8-28-32.png

    Then it works perfectly.
    How are you doing it differently?
     
  13. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    Yes! Yhat's exactly what I'm seeing.

    So on my machine using two different versions of cinemachine - the package manager one, AND a beta I was sent of a newer (sexier) version, the Paste Component Values only copies values into that top section, not to any of the rigs. Basically the gear produces this result:
    https://forum.unity.com/threads/copying-properties-from-play-mode-onto-prefabs.532085/

    I'm really sorry this has been so hard to track down. Do you think the behavior repro-'d above is fixable?
     
  14. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    heres when you know its bad

    upload_2018-6-25_22-42-34.png
     

    Attached Files:

  15. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    notice there are no rigs now in the prefab:

    upload_2018-6-25_22-44-47.png
     
  16. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    @mradfo21 Thanks for your persistence and patience!
    I was able to identify and fix a bug that was causing Paste Component Values to only paste the top section of the FreeLook. That fix will be in the next CM update.

    For the orphaned rigs in the scene view, I don't know how you're getting them unless you dragging and dropping a FreeLook onto a prefab FreeLook. In that case, Unity displays this warning dialog:

    upload_2018-6-26_15-56-7.png

    My advice to you: Don't do it. Just say no.

    The correct way to modify a prefab FreeLook is to paste the values onto an instance, then apply that instance back to the prefab.

    upload_2018-6-26_15-58-33.png

    If you do it like that, you won't get any orphan rigs.
     
  17. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    Yeah I've been replacing just to get around the copy paste issue. So it sounds like with the next update this wont even be an issue! I'm super happy you could see that on your end. Cant wait for the new Update! Any ETA on that?

    Great work Gregoryl !
     
  18. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    New update should be available in Preview within the next few days, I'll let you know when it's there.
     
  19. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    This is still suuuuper painful. Any chance this update is coming soon?
     
  20. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Yes, there is a new CM version (2.2.6) in Preview, which is waiting for a final QA pass before it can be released officially. You can grab it from there if you really need it.
     
  21. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    Any news on this? It's still destroying my work constantly... would LOVE a fix
     
  22. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    The current version of CM (2.2.7) will not create orphan rigs, provided that you follow the recommended workflow when working with prefabs: drag them into your scene, work on then there, hit Apply, then delete them from the scene.

    I'm not sure what you're doing to get the corruption.
     
  23. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    Yeah I really wish you could use the gear icon to copy settings between Cinemachine free look cameras but again it never fills in any of the composer values. It'll only take from the top with field of view etc.

    I'm using 2.2.7

    When the corruption occurs on the camera prefabs it always throws an error about "repainting" something. I feel really bad because I know you've been working on this and I keep hearing about this being patched but It really continues to happen. I no longer drag a prefab from the hierarchy to copy the settings (despite that being the only method that works) because I do get why that would cause the corruption. I'm currently working on abstracting cinemachine free look settings into a scriptable object per camera because it's the only way to tweak the values while the game is running (since my cameras are instantiated).

    I guess this is the end of the road if its officially been "fixed". You've definitely done a lot putting up with my complaints and maybe someone out there will get these new fixes and it'll work perfectly. Perhaps since i corrupted things they are broken permanently now *shrug. Hopefully the game gets to a place soon where I could package it up and send it to you so you could see the repro case. I just feel like your never gonna want to inherit my 30k codebase to try and solve a single bug.

    either way I'm just going to put as many of the CM settings into scriptable objects ... that seems to be my only hope.

    one thing I cant figure out how to access via script is the aim offset values for the orbits


    this is how i adjust the radius and the screen X, Y. I'm just not sure the syntax to adjust the aim offset on the 3 different rigs ?


    Code (CSharp):
    1.             CinemachineFreeLook cam = camera.gameObject.GetComponent<CinemachineFreeLook>();          
    2.  
    3.             for (int i =0; i < 3; i++){
    4.                     CinemachineComposer composer = camera.GetComponent<CinemachineFreeLook>().GetRig(i).GetCinemachineComponent<CinemachineComposer>() as CinemachineComposer;
    5.                     if ( cameraStateAsset.followTeamCenter == true){
    6.                         cam.m_Orbits[i].m_Radius = Mathf.Clamp(characterController.team.teamRadius * cameraStateAsset.teamRadiusBias, cameraStateAsset.teamRadiusMin, cameraStateAsset.teamRadiusMax);
    7.                     }
    8.  
    9.                     if ( cameraStateAsset.radiusControlsYoffset == true){
    10.                         float yoffset = Map(cameraStateAsset.yoffsetMin, cameraStateAsset.yoffsetMax, cameraStateAsset.fovDistanceMin,cameraStateAsset.fovDistanceMax, characterController.team.teamRadius);
    11.                         composer.m_ScreenY = yoffset;
    12.                         composer.m_ScreenX = cameraStateAsset.xoffset;
    13.                     }
    14.             }
     
  24. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    I'm really sorry to hear that you're still having trouble with this. If you're willing to put together a sample project with reliable repro steps, I'd be happy to have a look at it.

    For the aim offset, you want composer.m_TrackedObjectOffset.

    If you're willing to play around with experimental stuff, there is a new simplified FreeLook availabe in CM 2.2.8 (in preview). It takes a different approach from the old FreeLook, and doesn't use the hidden object children, which is the source of your prefab woes. To access it, you'll need CM 2.2.8, and you'll have to define CINEMACHINE_EXPERIMENTAL_VCAM in your player settings. Then, add the CinemachineNewFreeLook to an empty game object.

    The setup is a little different: you access Aim, Body, and Noise CM components directly as components on the game object. The settings apply to all three rigs by default. You then create customizations for the top rig and bottom rig, if you want them to be different from the main (middle) rig.

    upload_2018-11-2_15-37-6.png
     
  25. mradfo21

    mradfo21

    Joined:
    May 16, 2013
    Posts:
    194
    That's phenomenal! I'd been hoping things would go that way because often I really do keep most of the settings the same.

    I'm not too keen yet on using experimental features as i'm trying to keep things stable but Its just super cool to know that's coming.

    Thanks for the m_TrackedObjectOffset callout. Gonna put that in now!
     
  26. pierce0johnston

    pierce0johnston

    Joined:
    Sep 5, 2020
    Posts:
    1
    This just happened to me now, using Unity 2019.1.10f. How do I fix it and get my settings back?
     
  27. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    What version of Cinemachine are you using?
     
  28. MarcusJT

    MarcusJT

    Joined:
    Oct 3, 2019
    Posts:
    4
    I am having this issue with Cinemachine V2.6.2 and Unity 2019.3.15f1
     
  29. fishwind

    fishwind

    Joined:
    Jul 21, 2013
    Posts:
    11
    Hi there, I also experienced the exact issue when dragging freelook instance onto a freelook prefab.
    Cinemachine V2.6.1, Unity 2019.3.9f1

    Update: I tried using the "Apply" button. Same issue occur :(.
    Luckily I have version control.......
     
    Last edited: Dec 29, 2020
  30. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Does this still happen with CM 2.7.1?
     
  31. VacantXie

    VacantXie

    Joined:
    Dec 18, 2020
    Posts:
    3
    Yes and Yes in 2.7.2
     
  32. botove

    botove

    Joined:
    Apr 10, 2015
    Posts:
    52
    yeah, for last year or so i experience same stuff on different versions of unity and cinemachine (use latest) when working with cinemachine virtual camera as prefab. freelook loses it's rig info and create those three rigs outside it in scene. it's doesn't happen all the time, but randomly happens here and there while working with it, i can't notice any real dependency between my actions and when it happens. something wrong with prefab cinemachine workflow i assume
     
  33. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    If someone would give us clear repro steps we could fix it. We don't get that problem here.
     
  34. botove

    botove

    Joined:
    Apr 10, 2015
    Posts:
    52
    lost all rig info in freelook working with prefab today again (happens 50/50)
    1. have three cameras under prefab (prefab instance in scene)
    2. change parameters in those cameras (in prefab instance in scene)
    3. override apply them to prefab
    4. check other scene with this prefab instance or close/open unity

    made changes on all three cameras and they all lost rig stuff (the chang was "inherit position" tickbox)
    upload_2021-4-26_21-27-55.png
     
    Last edited: Apr 27, 2021
  35. gaborkb

    gaborkb

    Unity Technologies

    Joined:
    Nov 7, 2019
    Posts:
    856
    Unfortunately, we cannot reproduce the issue.

    @Sloppy-shorts, could you try recording the bug please? You can send the recording to me directly in a private message or create a bug report (> How to report bugs <).
     
  36. HandleBreaker

    HandleBreaker

    Joined:
    Dec 23, 2014
    Posts:
    2
    Same issue here cinemachine 2.6.4 unity version 2020.3.3f1
     
  37. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Good news! We have been able to reproduce this, and a fix is in the works
     
  38. botove

    botove

    Joined:
    Apr 10, 2015
    Posts:
    52
    Cool, big thanks!
     
  39. Blepius

    Blepius

    Joined:
    Mar 9, 2021
    Posts:
    68
    I'm experiencing randomly orphaned rigs in 2021.1.10f1. I don't know if I'm causing this or if it's related to this issue, it's very random?

    Was this issue resolved?

    edit: Maybe not so random.. this seems to occur when working with Cinemachine FreeLook prefabs.

    edit2 (edit3: I'm not able to reproduce behavior with the following steps, but these were the actions I took when it happened once. There must be something else I did?):

    1) Create a main camera and a Cinemachine FreeLook camera.
    2) Drag these into a folder to create prefabs.
    3) Change settings in your FreeLock camera in the scene Hierarchy.
    4) Drag the Cinemachine FreeLook scene camera onto the prefab from step 2
    5) Notice that BottomRig, MiddleRig, and TopRig now exist in the Scene Hierarchy.
     
    Last edited: Jun 16, 2021
  40. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    What version of Cinemachine are you using? There were recent fixes for this kind of issue. Try upgrading to the very latest preview version of CM in package manager.
     
  41. Blepius

    Blepius

    Joined:
    Mar 9, 2021
    Posts:
    68
    Version 2.7.4, I've just switched to com.unity.cinemachine@2.8.0-pre.1, and will let you know if it occurs again. It seems to be very fairly rare behavior, as far as I can tell.
     
    Gregoryl likes this.
  42. Blepius

    Blepius

    Joined:
    Mar 9, 2021
    Posts:
    68
    Hello again, I'm currently in version 2021.2.0b2 (Cinemachine 2.8.0-pre.1) and this issue seems to still be happening.

    The preceding action is to: drag and drop a Cinemachine Freelook Prefab (from the scene Hierarchy) onto it's original Prefab (in the Project folder) as a way to update Cinemachine settings.

    A simple Ctrl+Z and try again is a very simple workaround. However, should the user not notice the dropped rigs, this will result in lost work.
     
    Last edited: Jul 8, 2021
  43. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    Thanks for the update. I tried what you said with the same versions of CM and Unity, and cannot repro. If you can repro consistently, can you make a small repro project and log a bug please? That way, it will get tracked properly.
     
  44. Blepius

    Blepius

    Joined:
    Mar 9, 2021
    Posts:
    68
    Unfortunately it's not reproducible for me either, but if I figure out more, I will submit a repo for testing.
     
    Gregoryl likes this.
  45. Rumbleball

    Rumbleball

    Joined:
    Feb 25, 2022
    Posts:
    6
    +1
    Unity 2020.3.30
    Cinemachine 2.6.11

    Got a nice setup and suddenly everything was totally weird.
    Null ref log messages as mentioned by the others.
    Wanted to check the rig config on the prefab instance and was not able to find the Top/Middle/Bottom rig settings.
    Thought I go cracy, they've been there...
    Then I found them as mentioned by the others in the hierarchy of the scene.

    Got a simple Prefab with a CinemachineFreelook as first child. Setting y-axis/x-axis properties and orbit height/radius via script from the root object. Not accessing the rig components themself.

    Happend only once yet. Will keep my eyes open and see if I can reproduce.
     
  46. FGRivera

    FGRivera

    Joined:
    Jun 3, 2013
    Posts:
    16
    Running into this problem myself now. I have FreelookCam prefab that when I try to save overrides, the prefab corrupts. Seems to happen every time. Seemingly though, if I unpack the prefab and save it as an entirely new prefab, it works. I haven't tried to repro in a fresh project but its happening consistently in my current project
     
    qwertylevel3 and Bezoro like this.
  47. DeadCastles

    DeadCastles

    Joined:
    Sep 23, 2019
    Posts:
    14
    Having this same problem when I instantiate a prefab of my virtual camera.

    Unity 2020.3.25f1
    Cinemachine Version: 2.6.11
     
  48. pietro0games

    pietro0games

    Joined:
    Jun 5, 2017
    Posts:
    4
    I can't find a fix for this cinemachine prefab corruption. It seems to happen after updating the package. Removing and intalling the package doesn't fix. Someone knows if this corruption issue doesn't happen on 3.0.0?
     
  49. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,724
    CM 2.x has issues with prefabs, because the CM components create hidden child objects and the prefabs don't like it. You can work around this by using prefabs in a special way:
    • You can add a CinemachineVirtualCamera or CinemachineFreeLook to a prefab asset
    • In a prefab instance, you can override anything inside those components
    • You cannot add a CinemachineVirtualCamera or CinemachineFreeLook component to a prefab instance or variant. You must add those components in the base asset.
    CM3 solves this problem by removing the hidden gameobjects. However, CM3 isn't released yet and won't work with any version of Unity less than 2022.2. Upgrading an existing to CM will not in general be a simple matter, because the API has changed considerably, and will likely change some more before it is released.
     
  50. graskovi

    graskovi

    Joined:
    May 28, 2016
    Posts:
    14
    This is very interesting news! I hadn't heard about a new major version for Cinemachine, I have a few questions since I recently updated a project I'm working on to 2022.2 on that uses a CinemachineFreeLook component for a 3rd person camera.

    Obviously the exact release date will be up in the air, but do you have a sense of what Unity version V3 will be released with? Could it potentially be released sometime around or in the months following the 2022 LTS release?

    Since it sounds like there'll be some major API changes I'm curious what the tradeoffs are in terms of upgrade effort vs the benefits of the new system. I have a facade class that wraps the various FreeLook members and methods that I need (mostly the axis values, bias, rig heights & radii, recentering times & delays, and very importantly world space rotations x-axis limits) and only have one prefab to update. In cases like these will there be functionally equivalent members and methods to update these kinds of things? What I'm asking here is less "can I update my project without any work" and more "will there be similar functionality from V2 that can be translated without a major rethink".

    The fix for prefabs corruption sounds great! That'd make me much less paranoid about editing the prefab outside of prefab mode. What other kinds of fixes, improvements and features can we expect? Since you mention that 2022.2 will be the minimum required version will this integrate with the new Splines package that was released for Unity 2022? Looking around I also saw that in 2020 you brought up the possibility of using parts of the DOTS stack to improve performance. Is that work a part of this release, and if so would this release potentially make controlling cameras in DOTS projects easier? And I know there are things you can't talk about before release, but are there any fun new features you're excited for that you can talk about?

    Looking forward to the new release!


    EDIT: turns out there's a forum post for it: https://forum.unity.com/threads/announcing-cinemachine-3-0.1361713/ In short, yes native splines are used now, there's a very nice upgrade guide that looks promising if I update to Unity 2023, V3 won't play nice with DOTS, and the pre-release will be for 2023.1 and full release for 2023.2. All around exciting stuff!
     
    Last edited: Dec 21, 2022
    gaborkb and Gregoryl like this.