Spawn object with 3d ui

Hello all,
I have some trouble, when spawning an object with attached UITrait from the following example:

When I spawn such an object I got an exception in armory_examples/ui_script3d/Sources/arm/UITrait.hx at line 34 (the cast).

var = cast(object, iron.object.MeshObject).materials[0];

Make sure the object ui is attached to have a material with empty texture slot
if above doesn’t work than can you paste the full error?

The object has a diffuse material with empty texture. It works without exception, when I manually duplicate the object in blender. But when I spawn these object from a Trait attached to the scene, it comes to an exception.

can you paste the error here? so, i can see what’s wrong

Does the ui_script3d example work for you? The example is’nt working for me, because I can’t press the button. So also the gate doesn’t open or close.

But I tried to reproduce your error and also got a exception.

I added the following haxe trait to the scene of the ui_script3d example:

package arm;

class MyTrait extends iron.Trait {
	public function new() {

		notifyOnInit(function() {"Plane", null, function(o) {});

and got the following exception:

Uncaught exception:
var mat = (js_Boot.__cast(this.object , iron_object_MeshObject)).materials[0];
TypeError: Unable to get property ‘materials’ of undefined or null reference
at sceneInit (krom.js:406:3)
at iron_Scene.prototype.notifyOnInit (krom.js:6933:4)
at Anonymous function (krom.js:389:3)
at iron_data_Data.getFont (krom.js:7842:3)
at arm_UITrait (krom.js:387:2)
at Type.createInstance (krom.js:189:2)
at iron_Scene.createTraitClassInstance (krom.js:6297:2)
at iron_Scene.createTraits (krom.js:6224:4)
at iron_Scene.prototype.returnObjectLoaded (krom.js:6900:4)
at iron_Scene.prototype.returnObject (krom.js:6864:4)

The exception was in UITrait.hx at line 34 as you told, because object is null.

When duplicating the object manually in blender, the object is not null in line 34.
So I think there is a bug in the spawnObject function.

1 Like

It works after some modifications I have to scale the plane and move it down, because the buttons are not reachable out of the box.

Thanks for your work to reproduce the error. I did it a similar way and get the same exception.