Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added engine detail to Camera.yaml #1053

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

C-Corpze
Copy link

A detail about camera behavior such as cameras getting parented to nil when Workspace.CurrentCamera is set to another camera.

Current Roblox documentation lacks information about what happens when multiple camera objects are present in Workspace and the CurrentCamera property is changed to a different camera.

Cameras randomly being parented to nil might seem confusing and like some kind of bug if you can't even find anything about it in the documentation.

A detail about camera behavior such as cameras getting parented to `nil` when `Workspace.CurrentCamera` is set to another camera.
@C-Corpze C-Corpze requested a review from a team as a code owner March 18, 2025 13:55
@github-actions github-actions bot added the engine reference Changes the Engine API Reference documentation label Mar 18, 2025
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @C-Corpze, thanks so much for helping improve the Roblox creator documentation! Our technical writing team will review your pull request soon. In the meantime, please ensure you've read through the README.md, contribution guidelines, and style recommendations.

@IgnisRBX
Copy link
Contributor

IgnisRBX commented Mar 18, 2025

Hi @C-Corpze ,
Good point to add, thanks! I assume that "discarded" Cameras will follow typical garbage-collection behavior and actually get destroyed unless you're holding on to them through a script or similar? In other words, once Workspace.CurrentCamera is changed and the other Cameras are parented to nil, I assume that they are eventually garbage-collected and destroyed unless there's some intentional script or link that's keeping them around?

@C-Corpze
Copy link
Author

I'm uncertain if cameras are GC'd when parented to nil, not entirely sure how to test this again.

What I did was create a bunch of cameras and whenever something changed, I would print their parent and attempt to reparent them back into workspace.

I found out about this weird behavior when I was coding my own camera system from scratch, where I intend to have multiple camera objects that each can have their own independent post-processing effects and whatnot.

I honestly wish this was customizable as I find it quite inconvenient at best that this keeps happening, I cannot rely on cameras always existing and instead have to implement some additional code checks to make sure I'm not trying to set the CFrame of something that is nil.

@IgnisRBX
Copy link
Contributor

Hi again @C-Corpze ,
Curious, how and when are you creating the additional cameras? I did a bit of testing and additional cameras don't seem to replicate at all once play begins, even if they're parented somewhere outside of Workspace. Are you creating them in a script after play begins?

@C-Corpze
Copy link
Author

C-Corpze commented Apr 3, 2025

Hi again @C-Corpze , Curious, how and when are you creating the additional cameras? I did a bit of testing and additional cameras don't seem to replicate at all once play begins, even if they're parented somewhere outside of Workspace. Are you creating them in a script after play begins?

To clarify, I simply create camera objects on the client using a local script and then parent them to workspace.
From the moment CurrentCamera is changed, the previous camera will be parented to nil.
This behavior is consistent and keeps happening.

I assume the same thing happens on the server as well when it's done in a server script.
Although, typically you don't create cameras on the server so this is of course not tested yet.

Comment on lines +35 to +42

Warning:
It should also be noted that when changing `Workspace.CurrentCamera` to a new `Camera`
and there is more than a single `Camera` present in the top-hierarchy of `Workspace`
then all other unused `Camera` objects shall be parented to `nil` but not `Destroy()`d.

If you require a `Camera` to stay around, it is recommended to parent it inside a `Model` or object other than directly under `Workspace`.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Warning:
It should also be noted that when changing `Workspace.CurrentCamera` to a new `Camera`
and there is more than a single `Camera` present in the top-hierarchy of `Workspace`
then all other unused `Camera` objects shall be parented to `nil` but not `Destroy()`d.
If you require a `Camera` to stay around, it is recommended to parent it inside a `Model` or object other than directly under `Workspace`.
#### Storing Multiple Cameras
Note that when changing `Class.Workspace.CurrentCamera` to a new `Class.Camera`,
all other `Class.Camera|Cameras` directly descending from `Class.Workspace` will be
destroyed. If you need to store multiple cameras and swap between them on demand,
it's recommended that you store them in a `Class.Folder` or `Class.Model` under
`Class.Workspace`, inside which they will remain even when
`Class.Workspace.CurrentCamera|CurrentCamera` is changed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this sound? I rephrased to say effectively the same thing, and advised using a Folder as another option to a Model to contain the cameras.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engine reference Changes the Engine API Reference documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants