Docs say that factory.create
's url argument accepts types string, hash and url. However, when I try to pass the hash of the url of the factory component I want to use, I get an error: Instance (null) not found
.
When I pass a string of the same value as the hash, there is no problem.
Is the doc outdated, or it’s a bug, or I am doing smth wrong? Thanks!
Could you post the code you use here? It is hard to tell without seeing what you have done.
When you pass a URL it can either be as a string “foo#barfactory” or msg.url(“foo#barfactory”) or msg.url(nil, “foo”, “barfactory”). The URLs in my example are relative. An absolute URL would be “collectionid:/foo#barfactory” or “/foo#barfactory” but typically “foo#barfactory” is enough unless you have a complex scene built from multiple collections.
As you can see from the above there’s a bit of intelligence in how URLs are resolved. You don’t need to specify all parts.
When it comes to hashes they need to be specific and use the exact id if a component. In our example it has to be hash("/foo#barfactory") Note the slash at the beginning of the id.
So I was building a url with msg.url(string)
and then setting hash value as fragment.
Following the responses, I went over other variants with a more straightforward approach:
String and URL result in successful factory.create
, but both hashes result in Instance (null) not found.
Main.collection:
The URL with the hash is wrong. Doing it like that is likely the same as this:
msg.url(hash("/cards#cards_fac"), nil, nil)
This constructs a URL where socket is set to the hash while path and fragment are nil. Print the constructed URL to see how it resolves. This should on the other hand work:
factory.create(hash("/cards#cards_fac"))
Thanks for the suggestion - creating url with 3 discrete components, any of which can be hash, works well:
local url1 = msg.url(hash("main"), hash("/bar"), hash("factory"))
factory.create(url1, vmath.vector3(100, 100, 1))
Hash tho doesn’t seem to work:
factory.create(hash("main:/foo#factory"))
Can be checked at: sample code
Yes, looking at the engine code for resolving a URL from a hash value, it’s expecting the “path” part of the url. In this case that means the “/bar” part. However, for the factory.create() function to work, it needs the fragment part as well, or it cannot find what factory component to use.
I think it’s a bug that we accept hashes for the factory.create() function, but we’ll see. I will discuss this with the team tomorrow.