"The component could not be found" (SOLVED)

Currently experimenting, but I cannot seem to get a factory to work.

I have one spawned inside the collection, and when the collection is enabled, it attempts to ‘create’ using the factory. I’ve confirmed the URL of the factory is correct (changing it provides an error stating it’s wrong). I’ve also confirmed the “prototype” the factory spawns is valid, as I can throw it in the collection and it renders fine (it’s just one sprite).

The error given is “The component could not be found” which is being given from factory.create, with no more details about what the error actually is. Google and searching on here didn’t turn up much help.

Check the zip here for a working factory example

@Pkeod Thanks, it appears that referencing the factory without the parent object (ie “#factory” instead of “factories#factory”), causes the error. I had ruled that out as a factor as calling a factory that doesn’t exist at all (ie “#bob”) throws a different error.

1 Like

Ran into the same problem. Copied the code from sample project.
Spending my time on a very basic thing. It is frustrating =(((
I’m using defold 2.0 editor, still think it is not something with version of editor but with something I’ve forgotten. Do the engine code is missing some internal checks or meaningful error output?

Could you show us the code snippet for the creation and also tell us where the script is located in the collection?

I have level.script, it is located in main folder (for now), to manage my levels, spawn units, etc.

I have level folder, which has level.atlas (one picture with level background), level.go (sprite from level.atlas, script to /main/level.script)

I have goblinunit folder, which has
goblin_unit.atlas (several pictures for flipbook animations, with several animation groups),
goblin_unit.script (empty default script), goblin_unit.go (script + sprite),
goblin_unit_collection.collection (game_object from file goblin_unit.go, empty game_object “go” with the child factory id = “goblin_unit_factory”, prototype = “/goblinunit/goblin_unit.go”)

In my level script I try to spawn goblin_unit:


local unit = nil

function update(self, dt)

	if unit == nil then
		unit = factory.create("#goblin_unit_factory", vmath.vector3(500, 200, 0), nil, {}, 2.0)
	end
end

Remember that the folder structure has nothing to do with how collections, game objects and components relate to each other at run-time. What matters is the hierarchy you create in your collection and among your game objects.

If your level.script has this line:

unit = factory.create("#goblin_unit_factory", vmath.vector3(500, 200, 0), nil, {}, 2.0)

then it is expected that there is a factory component with the id goblin_unit_factory on the same game object as the level.script component. If you get a “The component could not be found” error then it’s because there is no factory with that id on the game object that level.script is attached to. Either create that factory or change the URL to point to the location of the factory (which seams to reside in the goblin_unit_collection.collection).

1 Like

Thank you, man.

I moved factory into level.go and it started to work!

Either create that factory

I have not created factories in runtime yet (will look at this feature and experiment with it a bit later).

I cannot make this path work. I have goblin_unit_collection.collection with game_object named go inside it. In that game_object I have factory with id=test_goblin_factory, url=/go#test_goblin_factory

When I call

unit = factory.create("/go#test_goblin_factory", vmath.vector3(200, 200, 0), nil, {}, 2.0)

I get console message
Instance /go#test_goblin_factory not found

Could you please open your main/bootstrap collection and screenshot the Outline with everything expanded. It’s really hard to try to figure out how you have structured your hierarchy from your descriptions.

1 Like