View Issue Details

IDProjectCategoryView StatusLast Update
0024857RunnerViews / CamerasPublic2021-07-29 15:32
ReporterRoss ManthorpAssigned ToCoreTech 
PriorityHighSeverityC - GeneralReproducibility100%
Status ResolvedResolutionFixed 
PlatformWindowsOSWindows 10OS VersionWindows 10
Product Version 
Target VersionFixed in Version 
Summary0024857: Cameras: [GMS2] Impossible to retrieve camera ID from camera update script
DescriptionThere is currently no way to get the id or view index of the camera currently calling the update script. The script returns these values correctly for both "begin" and "end" scripts.

In update, both view_current and camera_get_active() always equal 0.

I have attatched a project .yyz.
Here is the output from the project script, which has a camera bound to view 1.

Current View: 0
Current Active Camera: 0
Current View: 1
Current Active Camera: 17
Current View: 1
Current Active Camera: 17

Both "begin" and "end" function as expected, but this leaves camera update scripts pretty much useless on a per-camera basis - you might as well use end step. SAMPLE URL:
Additional Information
Tagsrendering, Runner
1.4 Found In
2.x Runtime Found In2.0.3.32
2.x Runtime Verified In


Mike Rennie

2016-12-09 14:52

Developer   ~0050666

I am a bit wary of hacking the view_current variable and camera_get_active() function to return something that doesn't reflect what is actually happening. camera_get_active() should return 0 at the point the scripts are run as that is what the active camera actually is (the default camera). The point of the update scripts is to modify the cameras before they are made active, so they are run before any of the views are processed.

I agree that it would be handy to be able to query which camera the script is associated with, but at the moment you can just have different scripts for different cameras.

Would it be worthwhile adding a new function such as camera_get_for_current_script() or something which is valid only inside the update\begin\end scripts and returns which camera the currently executing script is associated with?


2016-12-17 19:53

Viewer   ~0050741

Other possible design choice would be to add a "rest-parameter" to camera_set_*_script, which would determine the arguments that the script would be called with. This way the script could be passed it's camera ID as well as any other parameter's without having to create new scripts.


2017-04-04 12:33

Reporter   ~0052608

Last edited: 2017-04-04 12:34

View 2 revisions

[I got a message asking for my feedback as the reporter on this - I'm new to this, so sorry in advance for any confusion]

I definitely feel that there should be a way to retrieve the camera in the current script.
I think the "camera_get_current_for_script()" or perhaps a "camera_current" read-only variable (less typing) would be good options. I also like the idea of being able to pass the ID of the camera via an argument set - I imagine it would need to be an optional argument now that GMS2 is out of beta.
The point is to modify cameras before they are active, and you could have a different script for every camera, but this presents two immediate problems to me - the first is script clutter, the second is that you still need the camera ID to modify the camera in any way at all, which you'd need to pass to the script in some way - perhaps via a global. But that is just a workaround - I feel it is important for the camera-specific functions to have direct access to the calling camera, without messy workarounds.
My preference is the camera_get_current_for_script()/camera_current method. I think it would be helpful if this was consistent in begin and end scripts too, but I don't know how viable this is without knowing how everything works internally.

Those are my thoughts at least.


2021-07-29 15:32

Developer   ~0066538

No longer reproduces in v2.3.3. Closing.