I was recently try to make a CameraHandler script, that includes a HoldScriptable method which changes the CameraType property of CurrentCamera to Enum.CameraType.Scriptable, It works fine every time but, when fired immediately after the game starts, but something changes it back to Enum.CameraType.Custom, To check whether my other scripts weren’t messing this up, I created an empty project and added this localscript to ReplicatedFirst :-
local B = workspace.CurrentCamera
B.CameraType = Enum.CameraType.Scriptable
function A()
print("Current Cam type: ", B.CameraType)
end
game["Run Service"].PreRender:Connect(A)
And it outputs this:
Current Cam type: Enum.CameraType.Scriptable (x37) - Client - LocalScript:6
Current Cam type: Enum.CameraType.Custom (x95) - Client - LocalScript:6
After 30 to 50 frames or so, some internal code changes it back to Enum.CameraType.Custom
How do I disable this behavior or how do I know this behavior has finished happening so I can change it afterwards?
EDIT:
Also:
If I don’t set CameraType to Enum.CameraType.Scriptable, It prints Enum.CameraType.Fixed instead of Enum.CameraType.Scriptable.
from what I discovered it will changed to custom type when player character spawn while CameraSubject is nil
I think it’s engine level stuff since I can’t find code related to this anywhere (I maybe wrong)
you can do workaround by set CameraSubject to anything before set CameraType to scriptable I have tried set it to workspace and it no longer set back to custom now with following code
local B = workspace.CurrentCamera
B.CameraSubject = workspace
B.CameraType = Enum.CameraType.Scriptable
function A()
warn("[Current Cam type: ", `{B.CameraType}]`, "[Subject:] ",`{B.CameraSubject}]`)
end
game["Run Service"].PreRender:Connect(A)
Yea, It does work but, I fixed it! Do you know why does this behavior happen? I think it is possible that it is in PlayerModule generated by Roblox in the PlayerScripts folder of Player, There is OnCameraSubjectChanged method in PlayerModule.CameraController, is that whats responsible for this?