# React and Babylon.js - dealing with textures (scene parameter - null?)

**URL:** https://forum.babylonjs.com/t/react-and-babylon-js-dealing-with-textures-scene-parameter-null/35511
**Category:** Questions
**Created:** [November 8, 2022, 3:23pm UTC](https://forum.babylonjs.com/t/react-and-babylon-js-dealing-with-textures-scene-parameter-null/35511 "2022-11-08T15:23:56Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![nogalo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nogalo/32/120_2.png) [@nogalo](https://forum.babylonjs.com/u/nogalo)
#### Post date: [November 8, 2022, 3:23pm UTC](https://forum.babylonjs.com/t/react-and-babylon-js-dealing-with-textures-scene-parameter-null/35511/1 "2022-11-08T15:23:56Z")

</div>

Hi

I started using React, Typescript and Babylon as my new stack, and I am still looking for best approaches and practices to create my own boilerplate for the 3D projects.

One issue I encountered is this.

I want to have the structure like this

1. **images.ts** (where I load all images that I need to create textures from)  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/0/3/03717cab4181e9384cb58988920d8dd3699c92aa.png)

2. **textures.ts** (where I create texture from the images defined above)  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/d/b/dbc219857482c92c18fe8be5d3e0abbb9cd06f8c.png)

So furthermore I can have like materials.ts and so on.

The point is that in **textures.ts** I don’t have a “scene” parameter (scene probably is not even created yet at this point). So I can pass “null” as an argument for scene. But this doesn’t work for VideoTexture. Texture has scene as optional parameter, while VideoTexture does not, so I am getting error at runtime.

![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/c/e/ce993f097cfef2742f31e506fee8e308508b8d25.png)

Makes sense I guess. But I don’t know how to deal with this issue. I would appreciate any ideas that could help improve the structure and fix this issue.

Thanks

---

<div class="post-metadata">

### Author: ![sharp](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sharp/32/1325_2.png) [@sharp](https://forum.babylonjs.com/u/sharp)
#### Post date: [November 8, 2022, 4:18pm UTC](https://forum.babylonjs.com/t/react-and-babylon-js-dealing-with-textures-scene-parameter-null/35511/2 "2022-11-08T16:18:19Z")

</div>

Hi,

You should try to convert your video to mp4 because \*.mov is no longer widely used on the internet. Apple itself generally now uses MP4 for video.

---

<div class="post-metadata">

### Author: ![sharp](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sharp/32/1325_2.png) [@sharp](https://forum.babylonjs.com/u/sharp)
#### Post date: [November 8, 2022, 4:26pm UTC](https://forum.babylonjs.com/t/react-and-babylon-js-dealing-with-textures-scene-parameter-null/35511/3 "2022-11-08T16:26:00Z")

</div>

> [@nogalo](#):
>
> I started using React, Typescript and Babylon as my new stack,

Good stack :), did you try [vite](https://vitejs.dev/) ?

---

<div class="post-metadata">

### Author: ![nogalo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nogalo/32/120_2.png) [@nogalo](https://forum.babylonjs.com/u/nogalo)
#### Post date: [November 8, 2022, 4:48pm UTC](https://forum.babylonjs.com/t/react-and-babylon-js-dealing-with-textures-scene-parameter-null/35511/4 "2022-11-08T16:48:03Z")

</div>

Hey.

Thanks for the advice. I intended to convert those to mp4 at some point 😃  
As for the Vite. I just recently started to encounter Vite, and I will most likely include it in my workflow really soon. Need to do some more research though.

---

<div class="post-metadata">

### Author: ![brianzinn](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/brianzinn/32/28013_2.png) [@brianzinn](https://forum.babylonjs.com/u/brianzinn)
#### Post date: [November 8, 2022, 6:32pm UTC](https://forum.babylonjs.com/t/react-and-babylon-js-dealing-with-textures-scene-parameter-null/35511/5 "2022-11-08T18:32:44Z")

</div>

if you have the scene ref (useRef?) in your calling code you could try something like:

```typescript
// in textures.ts - you can add a guard clause scene isn't null if you want
const posterPenguin_texture = (scene: Nullable<Scene | ThinEngine>) => new VideoTexture(posterPenguin, scene, false, false);

// in calling code
import posterPenguin_texture from './textures.ts';

// set the scene somewhere
const sceneRef = useRef<Scene|null>(null);
...

posterPenguin_texture(sceneRef.current);

```

hard to say without full code, but also if you put the images in /public then you can serve them and your browser will cache them and load on demand. I think what you have there will bundle videos/images.

edit: the error may be how you are passing in the images. you may need to base64 encode and put in `data:...` - I haven’t tried with imports before that way.

---

<div class="post-metadata">

### Author: ![nogalo](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/nogalo/32/120_2.png) [@nogalo](https://forum.babylonjs.com/u/nogalo)
#### Post date: [November 8, 2022, 8:22pm UTC](https://forum.babylonjs.com/t/react-and-babylon-js-dealing-with-textures-scene-parameter-null/35511/6 "2022-11-08T20:22:56Z")

</div>

Hey. I actually solved the issue the with almost exact way you explained.

It is plausible for now. Will probably try to look for more elegant solution in the future.

Thanks @brianzinn. I will mark your answer as solution, as that’s pretty much how I solved it. Also, I will probably ping you from time to time if I need some help, as I am looking for “perfect” architecture to combine Babylon and React, and so far I have many issues that I am slowly clearing up, but from time to time something weird pops up.
