Unity-Technologies / com.unity.cinemachine

Smart camera tools for passionate creators
510 stars 117 forks source link

FreeLook Cam Issue #410

Closed BhawanVirk closed 8 months ago

BhawanVirk commented 2 years ago

Free Look cam is not working by default. I did have assigned follow and look at target. After pressing play button, main camera does not do anything and also every time I select free look cam gameobject (btw this gameobject is prefab) I get the error I pasted at the bottom. But if you disable and re-enable free look gameobject at runtime it starts to work like normal.

Produced In Unity Version: 2021.2.11f1

Error In Editor: NullReferenceException: Object reference not set to an instance of an object Cinemachine.CinemachineFreeLookEditor.DrawFreeLookGizmos (Cinemachine.CinemachineFreeLook vcam, UnityEditor.GizmoType selectionType) (at Library/PackageCache/com.unity.cinemachine@2.8.4/Editor/Editors/CinemachineFreeLookEditor.cs:178) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

glabute commented 2 years ago

It sounds as though your scene is corrupted with an orphan vcam with the same priority as the FreeLook. Try to find it and delete it. There are some elusive issues that crop up from time to time when editing FreeLook prefabs, but we have not been able to reproduce them. If you could give precise repro steps for how to produce this situation from a clean project, it would be most helpful.

BhawanVirk commented 2 years ago

It turns out the free look cam prefab was corrupted in some way, it was creating multiple vcam gameobjects in scene with named Top Rig, Middle Rig, Bottom Rig and Rig tabs on free look cam component were not showing anything but with warning to assign follow/look target while I did have had assigned them. So I fixed it by first deleting all dummy vcam gameobjects from the scene and then I opened free look cam prefab and as I clicked on the free look component gameobject it had (Top Rig, Middle Rig, Bottom Rig) as child gameobjects. Then I deleted these child gameobjects, but everytime i clicked on freelook cam gameobject it was recreating these three child gameobjects again. So I ended up deleting freelook cam component in prefab and saving the prefab as empty and reopening and assigning new freelook cam component again in prefab and then it starts to work like normal. Btw when prefab was corrupted, everytime I selected freelook cam gameobject in prefab it produced warning in editor saying VCCache != null or something.

glabute commented 2 years ago

The Top/Middle/Bottom Rig children of the FreeLook are supposed to be there, that's why they keep getting recreated. Normally they're hidden objects so you don't see them in your scene. When editing prefabs, however, they become visible. You should ignore them in the prefab, but if you ever see them orphaned in your scene, that's a problem. If you can find repro steps for how those orphan rigs get accidentally created, I would be grateful if you would communicate them to me.

BhawanVirk commented 2 years ago

I just reproduced it and I think plastic scm package is corrupting the freelook cam prefab. Here are the steps I performed (Its weird that they sometimes work and sometimes not)

BhawanVirk commented 2 years ago

Also if you couldn't produce this bug in first time, try closing and opening project

BhawanVirk commented 2 years ago

And also after this bug when you select prefab again you'll get 3 errors like this (One for each rig):

Setting the parent of a transform which resides in a Prefab Asset is disabled to prevent data corruption (GameObject: 'TopRig'). UnityEditor.Undo:SetTransformParent (UnityEngine.Transform,UnityEngine.Transform,string) Cinemachine.CinemachineFreeLookEditor/CreateRigWithUndo/<>c:<.cctor>b__0_0 (Cinemachine.CinemachineFreeLook,string,Cinemachine.CinemachineVirtualCamera) (at Library/PackageCache/com.unity.cinemachine@2.8.4/Editor/Editors/CinemachineFreeLookEditor.cs:141) Cinemachine.CinemachineFreeLook:CreateRigs (Cinemachine.CinemachineVirtualCamera[]) (at Library/PackageCache/com.unity.cinemachine@2.8.4/Runtime/Behaviours/CinemachineFreeLook.cs:559) Cinemachine.CinemachineFreeLook:UpdateRigCache () (at Library/PackageCache/com.unity.cinemachine@2.8.4/Runtime/Behaviours/CinemachineFreeLook.cs:625) Cinemachine.CinemachineFreeLook:GetRig (int) (at Library/PackageCache/com.unity.cinemachine@2.8.4/Runtime/Behaviours/CinemachineFreeLook.cs:173) Cinemachine.CinemachineFreeLookEditor:UpdateRigEditor () (at Library/PackageCache/com.unity.cinemachine@2.8.4/Editor/Editors/CinemachineFreeLookEditor.cs:109) Cinemachine.CinemachineFreeLookEditor:OnInspectorGUI () (at Library/PackageCache/com.unity.cinemachine@2.8.4/Editor/Editors/CinemachineFreeLookEditor.cs:81) UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

glabute commented 8 months ago

The CM3 refactor of freelook takes care of this issue