Problems with rendercam (SOLVED)

I’m really lost on this one.
I’m using the rendercam library, but for some reason I just can’t seem to refer to any camera. Every time I try to call this function,

rendercam.activate(cam_id)

I always get the warning that the camera wasn’t found. However, trying to fix this, I snuck some print()s in the activate_camera function, and as it turns out, the cam_id being used there is perfectly fine.

print(cam_id):

hash: [/level_cam]

pprint(cameras):

{
 hash: [/level_cam] = { --[[0000029D92F574E0]]
active = true,
following = false,
id = hash: [/level_cam],
aspectRatio = 1.7777777777778,
worldZ = 0,
useViewArea = false,
nearZ = -1,
lpos = vmath.vector3(0, 0, 0),
wupVec = vmath.vector3(0, 1, 0),
halfViewArea = vmath.vector3(0, 0, 0),
lforwardVec = vmath.vector3(0, 0, -1),
orthoScale = 1,
fov = -1,
viewArea = vmath.vector3(0, 0, 0),
follows = { } --[[0000029D92F57690]],
recoils = { } --[[0000029D92F57640]],
shakes = { } --[[0000029D92F575F0]],
lrightVec = vmath.vector3(1, 0, 0),
abs_nearZ = -1,
scaleMode = hash: [fixedArea],
wforwardVec = vmath.vector3(0, 0, -1),
wpos = vmath.vector3(0, 0, 0),
orthographic = true,
abs_farZ = 1,
farZ = 1,
fixedAspectRatio = false,
lupVec = vmath.vector3(0, 1, 0)
}
}

print(cameras(cam_id)) however is just nil. But I doubt that it’s the rendercam script’s fault, so here’s also how I call the function:

	local camID = go.get_id("/level_cam")
rendercam.activate_camera(camID)

And here’s how they are arranged in the collection (the above is being used in a script inside player.go), the collection is loaded as a proxy into the main collection.

I know that proxies are often troublemakers when it comes to addressing game objects, but I doubt that that’s the problem here. Anyway, as I said, I have no clue why this isn’t working, but I’m probably just missing something.
Does anyone know what’s happening here?

Hmm, are you trying to do this on init? Since the init order of objects is not predictable, the camera may not have init when you are trying to activate it.

If that’s the case, you can tick the “Active” checkbox on the camera script and it should activate itself when it gets init, or you can have your script delay activating the camera somehow (by sending a message to itself, with a timer, with a flag on the first update, etc.).

If you don’t mind sharing, you can zip up the project and I’ll take a look.

3 Likes

Thanks, that was it!
I moved the part over into the on_input function to only be executed on a specific button press, and once I pressed that button, the camera activates. I’m also using rendercam.follow(), and it also works perfectly. Funny how it’s always those really small things leaving you completely clueless lol.

2 Likes

Cool, glad that was it.

The real solution would be for me to add matching messages for those functions on the camera, since a message sent on init will arrive after everything has init. I think I did that in one of the other versions, but it never made it to the main branch. :man_facepalming:

3 Likes