(SOLVED) Collection Proxy/RenderCam error

I’m just getting started with learning about collection proxies and game structure, and I put the collection that contains the player, the RenderCam GO, and the first level (just to test), and had it load when the player pressed a button. While the collection loaded and everything almost seemed fine, I was getting a constantly repeating error in the console:

ERROR:SCRIPT: /rendercam/camera.script:178: function called can only access instances within the same collection.
stack traceback:
	[C]: in function 'get_world_position'
	/rendercam/camera.script:178: in function </rendercam/camera.script:140>

Hmm. Line 178 in the camera.script gets the position of an some object that you’ve set the camera to follow. Are you telling it to follow an object in a different collection proxy?

It should be set to the same collection proxy, but I think the path to the object is wrong, as I don’t know how to address objects inside collection proxies.

1 Like

To address objects in other collection proxies can be done like this:

Obtain the collections name:

Then get name of the game object. Also the particular child element, if needed.
In this case we’ll use a script file with Id, “script”.

To pass a message to the script, we’d use this.

msg.post("main:/controller#script", "unique_message_hash")

I don’t know if that will fix the error though… I’ve seen the same error but can’t remember what I did.

Perhaps post what your outline looks like with the camera object?

2 Likes

If either of you has a small project with this error that you can zip up and send to me (in the thread or by message), I would be happy to look at it.

Without more information I don’ t know what to say other than: make sure your URL is correct - try sending messages to it, using get_position on it, etc.

2 Likes

Sorry for the late response, but here you go. It seems like the problem isn’t an incorrect URL. I think it might be that if you address a collection at all, valid or no, it gives you an error.

OK, the first thing I notice, in your game.project, under Bootstrap >> Render, you’re not using the RenderCam render script. RenderCam won’t work at all unless you hook that up. That may not be the cause of the error though, so I left that for now.

If I open your ‘boop.script’ and remove the ‘rendercam.follow("boop:/boop")’ line, then the project runs with no errors, so we know it has something to do with that.

If instead I add a line:

msg.post(“boop:/boop”, “test”)

I get the following error:

ERROR:SCRIPT: /main/boop.script:9: Could not send message ‘test’ from ‘default:/boop#boop’ to ‘boop:/boop’.

Not the most descriptive error message, but this means there’s something wrong with our “boop:/boop” URL. Also it tells us that the URL of the boop.script instance is “default:/boop#boop”…

(You can also use ‘print(msg.url())’ in a script to find out its URL.)

If you open ‘collection.collection’ and click on the root “node” in the Outline panel, you’ll see in its properties that its name is “default” (not “boop”). You may want to change this.

If you look at the addressing manual, it says the URL format is:

[socket:][path][#fragment]

The ‘socket’ part is the “world” collection that the object is in. Normally this is your “main” collection (or whatever you have called it) for everything, but if you use collection proxies, it will be the name of your proxy collection (for objects inside that collection).

The ‘path’ part is the hierarchy of collections that the object is in, inside the world collection. Note: this is NOT the hierarchy of game objects. If you do something like this:

The URL path will still just be ‘/boop’ (as you can see in the properties panel). All game objects in the same collections must have unique names for this reason. Instead, if you add Collections (in separate files) that are nested, one inside the other, with ‘boop.go’ inside the last one, you will get this:

You can see in the properties panel that the URL path changes.


So, anyway…If you change your boop script to use ‘rendercam.follow("default:/boop")’, then you don’t get any errors. Do that and hook up the render script in your game.project, and it should work just fine.

A slightly better idea though, is to use ‘rendercam.follow(msg.url("."))’. The 'msg.url(".")' gives you the address to the current game object (without the “fragment”/component), which is what RenderCam needs for following. This way you don’t even need to know the URL, you change change things around however you want and it will still work.

There is a limitation, as your original error suggests, that you can’t get the position of an object in a different world. So, if you had your camera in main.collection, it could not follow objects in your proxy world, you would need to use another camera inside the proxy collection.

3 Likes

Oh, yet another caveat (!): if you use rendercam.follow() on init and your camera is in the same collection, it may just not work…This is because the init order of objects is semi-random, so in this case the camera has not initialized before you try to tell it to follow something. This is sort of solved in a top-secret newer version of RenderCam, which lets you send a “follow” message instead of a function call. The other solution is to have your script send a message to itself on init, and call rendercam.follow() inside that message response (which is guaranteed to happen after everthing has init).
If you want to use the newer version, see here for the documentation, and use this as your dependency link: https://github.com/rgrams/rendercam/archive/2.0Beta.zip

Probably this is way too confusing, so here’s a version of your project with everything working. I added some input (arrow keys) and a background so you can see it all working.
rcam proxy error test.zip (707.8 KB)

3 Likes

Thank you sooooo much!! I’ve been stuck on this for so long!

3 Likes