# Custom instance buffer trouble

**URL:** <https://forum.babylonjs.com/t/custom-instance-buffer-trouble/34403>\
**Category:** Questions\
**Tags:** material, shader, instances\
**Created:** [October 2, 2022, 10:02am UTC](https://forum.babylonjs.com/t/custom-instance-buffer-trouble/34403 "2022-10-02T10:02:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CodeCycle](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/codecycle/32/19068_2.png) [@CodeCycle](https://forum.babylonjs.com/u/CodeCycle)\
**Post date:** [October 2, 2022, 10:02am UTC](https://forum.babylonjs.com/t/custom-instance-buffer-trouble/34403/1 "2022-10-02T10:02:57Z")

</div>

Hello forum,

I have trouble using the registerInstancedBuffer feature. (How to pass custom attributes of each instance to the shader).

For example: [Babylon.js Playground (babylonjs.com)](https://playground.babylonjs.com/#YPABS1#177)

Thanks for any help!

---

<div class="post-metadata">

**Author:** ![slin](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/slin/32/36084_2.png) [@slin](https://forum.babylonjs.com/u/slin)\
**Post date:** [October 2, 2022, 4:37pm UTC](https://forum.babylonjs.com/t/custom-instance-buffer-trouble/34403/2 "2022-10-02T16:37:19Z")

</div>

See this PG with the fix: [https://playground.babylonjs.com/#YPABS1#181](https://playground.babylonjs.com/#YPABS1#181)

First, you cannot directly declare attribute in fragment shader. I pass the value of attribute test to fragment shader by using a varying `vTest`. And set `vTest` to be the value from attribute `test`.

```auto
    box.material.Vertex_MainEnd(`\
        vTest = test;
    `);

```

You also need to declare the custom attribute before using it.

`box.material.AddAttribute("test")`

---

<div class="post-metadata">

**Author:** ![CodeCycle](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/codecycle/32/19068_2.png) [@CodeCycle](https://forum.babylonjs.com/u/CodeCycle)\
**Post date:** [October 2, 2022, 4:47pm UTC](https://forum.babylonjs.com/t/custom-instance-buffer-trouble/34403/3 "2022-10-02T16:47:23Z")

</div>

Beautiful, thank you!
