Problem addressing sprite component (SOLVED)

Hey there,

I’m having an issue addressing a sprite component of a game object in a subcollection. Here’s my scene heirarchy:

Note that the url of the carrier object is /gift_carrier/carrier. When I select the carrier object’s sprite component though, the url is not /gift_carrier/carrier#sprite as I would expect:

Instead, the editor claims the url is /carrier#sprite. That’s a url that makes sense from within the gift_carrier collection, but I thought the absolute url should be /gift_carrier/carrier#sprite.

To make sure I wasn’t totally out to lunch, I inspected the url of the root object’s script component:

It shows an absolute url to the component, just like I think it should.

What’s going on here? This almost feels like a bug to me, like for some reason the editor isn’t calculating the correct absolute url for the carrier object’s sprite component.

My code in /gift_carrier/root#script tries to get the sprite id using a relative path:

self.carrier_sprite = go.get_id('carrier#sprite')

This call succeeds, but then later when I try to use the id, I get errors like:

go.get(self.carrier_sprite, 'size')
Could not find any instance with id '/gift_carrier/carrier#sprite'.

Can anyone shed some light on this one?

Thanks!

Ok, there’s definitely something buggy going on - I dragged the problematic sprite component and dropped it as a child of the root game object. Then I dragged it back to be a child of the carrier object again. Now the editor shows the correct absolute url:

However, I still get errors like this:

Could not find any instance with id '/gift_carrier/carrier#sprite'.

Oh, oops -

I think I was being dumb. I must have added this sprite component to the instance of the gift_carrier collection in my main collection. What I mean to do was add the component to gift_carrier.collection itself.

I think this explains why the sprite component was getting a url relative to the main collection.

Mmm, nope. Something fishy is still going on.

I made sure my gift_carrier.collection file was just as I wanted it, and then added it fresh to the main collection. The editor still shows the sprite component as having a url of /carrier#sprite and when go.get_id turns that into an absolute url (/gift_carrier/carrier#sprite), the instance still cannot be found.

Ok, problem solved:

I was wrong to try to use go.get_id to get an identifier for a component. I think it must be meant to get the ids of game objects only. I switched to using a url object, and now all is well:

self.carrier_sprite = msg.url('carrier#sprite')
...
go.get(self.carrier_sprite, 'size')
3 Likes