Creating/displaying scrollview dynamically

I’ve got it so when the player looks at a particular statue a scrollview comes up displaying some information to the player. In the project provided the cube on the left has the scrollview that was done in the editor which works fine, I’ve hooked it up with buttons that will scroll the window up and down by looking at them using the reticle in the centre of the screen.
The cube on the right I have attached a script that will create the same scrollview using the same parameters of each of the elements and been able to create it dynamically at runtime but the scrollbar does not appear and the buttons aren’t displaying correctly. Upon checking the console the dynamically created scrollview buttons are registering correctly(when moving the reticle in the centre of the screen over them), but there is no scrolling.

Forgive the messy button placement and formatting, wanted to make sure it would work first.

The scroll is not working and even the buttons dont appear to be displaying the correct color. What am I doing wrong?

Heres an example project of what I’m trying to do PlayCanvas | HTML5 Game Engine

Hi @Jasont and welcome,

Not sure what’s wrong with your code, but a good idea when doing runtime spawning of entities/objects is to prepare them in editor, keep them disabled. On runtime use that as a template/prefab to create a clone and spawn an exact copy of that editor prepared object.

var newEntity = prefabEntity.clone();
newEntity.enabled = true;

Not sure if that will solve your problem, but it can help to easily test where is the issue. If it’s something with the params you setup the entities or something different.


omg, Ive spent all day trying to get that working. Didn’t think of just cloning it. So much easier to do it that way.

Thanks so much.

1 Like