When looking for a client’s Camera object, developers should use this property rather than looking for a child of Workspace named ‘Camera’.
Why is it preferred to use current camera over workspace camera? the only scenario I can think of is if you have duplicate camera objects in the workspace but in what world would that ever happen accidentally? is there any other benefits to specifically using the current camera property over just directly indexing camera in workspace
Because CurrentCamera always points to the camera that’s set as your current one. Even though Roblox doesn’t allow multiple cameras in the workspace, that might change at some point, meaning you might have multiple instances named “Camera”.
That is what you do, but anyone can have anything called camera in the workspace, it could be a model of a physical camera, you never know. Just use the property it is guaranteed to give the correct instance.
Even if it were possible to have multiple camera instances in workspace, there should never be a reason to have that, its a safe assumption to say that there will only ever be 1 camera in workspace unless a accident happens and if that accident were to happen it would be easily fixed
Directly indexing for children is bad practice anyways, it is not forwards compatible as you are assuming Roblox won’t introduce a member with the same name as the child. Remember that class members have higher precedence over children when indexing. Use :FindFirstChild and :WaitForChild instead. So the advice given in the documentation is valid.
I don’t quite understand the example you gave, you can just modify the existing camera or if you have a specific camera object at the very least it should be parented to a model or even have a different name?
Directly indexing in this case should be quite valid? when your using .CurrentCamera that just a property referencing the camera object of the player viewport, even if there was a chance for camera to be nil the property(value) would be nil aswell, so the same argument can be made about directly indexing a proprety for the camera reference
Well I assumed the reason you mention waitforchild/findfirstchild was because the camera object might be nil when I reference it? (might of misread so extra clarification would be nice if I did get this wrong)
Instances can be nil in a sense that they didn’t fully load in yet, for example Player.Character is also a proprety and the proprety can be nil if the character hasent fully been loaded in yet or hasent been set yet by roblox back-end stuff which is why people tend to do
I was stating that if camera was impossible to become nil, then there no harm in directly referencing it without .CurrentCamera, unless obviously there was multiple objects with the same name
There is, you are assuming Roblox won’t add in a member named Camera as a part of Workspace. Use :FindFirstChild if you are so keen on avoiding the property.
Alright, I was just wondering why people use .CurrentCamera over just directly getting it from workspace, its not like im avoiding i was just curious thanks for your input
You can use Workspace.CurrentCamera is a property of the workspace and Workspace.Camera is an instance. Like both work, their is no one concrete method so there is no diffinitive method but Workspace.CurrentCamera is the more ideal method for finding the active camera.
Technically the main camera could be named something different than Camera, and there could also be more than one Camera (used for ViewportFrames). So you should definitely always use the CurrentCamera property if you’re trying to access the camera the player is using for the game viewport.