# Help Passing Properties with collectionfactory.create (SOLVED)

**URL:** <https://forum.defold.com/t/help-passing-properties-with-collectionfactory-create-solved/76443>\
**Category:** Questions\
**Created:** [March 28, 2024, 8:48pm UTC](https://forum.defold.com/t/help-passing-properties-with-collectionfactory-create-solved/76443 "2024-03-28T20:48:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fluid\_mosaic](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/fluid_mosaic/32/35547_2.png) [@fluid\_mosaic](https://forum.defold.com/u/fluid_mosaic)\
**Post date:** [March 28, 2024, 8:48pm UTC](https://forum.defold.com/t/help-passing-properties-with-collectionfactory-create-solved/76443/1 "2024-03-28T20:48:53Z")

</div>

Hello all,

I am trying to use my first collection factory and I cannot get it to properly pass properties to the collections it creates. I have created a spawn script which just attempts to distribute random game objects around the world and hopefully give them different sprites and values.

It works fine if I leave out the optional properties argument from the create function (however that means I have clones of the same collections spawning).

Here is the issue it raises, with the collectionfacotyr.create function:

```lua
     ERROR:SCRIPT: scripts/polypeptide_factory.script:17: bad argument #7 to 'create' (hash expected, got string)
        stack traceback:
          [C]:-1: in function create
          scripts/polypeptide_factory.script:17: in function <scripts/polypeptide_factory.script:3>

```

Here is my spawn script for the collections:

```
go.property("spawn_count", 10)
local imgs = {hash("gear"),hash("polypeptide sheet"),hash("spring")}
function init(self)
	math.randomseed(os.time())
	self.spawned_molecules = {}
	for i = 1, self.spawn_count do
		local p = go.get_position()
		p.x = p.x + math.random(-1000,1000)
		p.z = p.z + math.random(-1000,1000)
		
		local img = imgs[math.random(1,3)]
		local type = hash("polypeptide")
		
		pprint(img, type)
		local component = "#polypeptide_collection_factory"
		local props = {sprite_image = img, type = hash("polypeptide")}
		local id = collectionfactory.create(component, p, nil, props )
		table.insert(self.spawned_molecules, id)
	end

```

In the collection script I have these lines

```
go.property("type", hash("unspecified"))
go.property("sprite_image", hash("spring"))

```

and in the initialization I have set the sprite image with the following line:

```lua
msg.post("#sprite", "play_animation",{id = self.sprite_image})

```

This same code worked fine for a regular factory, so I am lost.  
Thanks for any assistance you can provide.

also-- I am new to Defold and game development in general and just want to give a big thanks to all the awesome people on these forums because I’ve already learned so much.

---

<div class="post-metadata">

**Author:** ![Potota](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/potota/32/33404_2.png) [@Potota](https://forum.defold.com/u/Potota)\
**Post date:** [March 28, 2024, 9:19pm UTC](https://forum.defold.com/t/help-passing-properties-with-collectionfactory-create-solved/76443/2 "2024-03-28T21:19:57Z")

</div>

You have to specify which object the properties apply to when using collection factories:

> **[API reference (Collection factory)](https://defold.com/ref/stable/collectionfactory/#collectionfactory.create:url-%5Bposition%5D-%5Brotation%5D-%5Bproperties%5D-%5Bscale%5D)**
>
> Defold is a free and open game engine used for development of console, desktop, mobile and web games.

---

<div class="post-metadata">

**Author:** ![fluid\_mosaic](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/fluid_mosaic/32/35547_2.png) [@fluid\_mosaic](https://forum.defold.com/u/fluid_mosaic)\
**Post date:** [March 28, 2024, 9:36pm UTC](https://forum.defold.com/t/help-passing-properties-with-collectionfactory-create-solved/76443/3 "2024-03-28T21:36:00Z")

</div>

I swear I read that passage but it didn’t sink in until you re-shared it.  
I have altered my properties and now it works like a charm (and it makes a lot of sense now too.)

```lua
props[hash("/game_resource#object")] = {sprite_image = img, resource_type = type}

```

Thank you!
