[SOLVED] rigidbody.raycastFirst() doesn't recognize my programmatically created rigidbodies

Editor: https://playcanvas.com/editor/scene/700970
Launch: https://launch.playcanvas.com/700970?debug=true
Script: https://playcanvas.com/editor/code/600366?tabs=18715844,18801293,17191804
(buildMode is the script attached to the Builder button, builder is a root script, itemPicker runs the selection script)

My builder script for ETA is nearly complete, as the user can now spawn tiles in any useful position or rotation. But after spawning the tiles, they can’t be selected for highlighting, ruler-ing, or token moving. I think the problem has something to do with the rigidbody of the tile. My rationale is that result.entity on the onSelect() function isn’t being assigned when a builder-spawned tile is clicked. This can be seen with console log messages on lines 103 & 110 of itemPicker.js

// Selection Function
ItemPicker.prototype.onSelect = function (e) {
    if(this.debug) console.log('Clicked Onto the screen');
    //
    // Converts the screenCoordinates from our mouse coursor into world space coordinates to be used for our engine
    var from    = this.entity.camera.screenToWorld(e.x, e.y, this.entity.camera.nearClip);
    var to      = this.entity.camera.screenToWorld(e.x, e.y, this.entity.camera.farClip);

    // do a raycast within our scene
    var result = this.app.systems.rigidbody.raycastFirst(from, to);
    
    // if we hit something
    if (result) {
        // get the entity we hit
        var pickedEntity = result.entity;
        console.log('Selected Entity Tag:', result.entity);

I imagine that I must have done something wrong when making the rigidbody script on line 66 of builder.js. But I can’t for the life of me figure out what it could have been.

Looks like my script is returning this:
image
So, as I thought, it was a problem with how I was creating the rigidbody. The weird thing is, I use pretty much the exact same script to spawn the tokens (e.g. line 189 in itemPicker.js), yet PlayCanvas doesn’t send the warning when ETA spawns a token. The error only occurs when ETA tries to spawn a tile.

token spawning script:

case 0:

// position of tile y += 0.075
goldPosition = pickedEntity.getLocalPosition();
var goldX = goldPosition.x;     var goldY = goldPosition.y + 0.075;     var goldZ = goldPosition.z;  // (re-) assign the vec3 coordinates
goldPosition.set(goldX, goldY, goldZ);

// spawn gold token and add it to the entity hierarchy 
this.app.root.addChild(goldToken);   // copy all these declarations outside switch statement to facilitate token moving

// add components (cylinder etc)
goldToken.addComponent("model", {type: 'cylinder',});
goldToken.addComponent("collision", {type: "cylinder", radius: 0.33, height: 0.15});
goldToken.addComponent("rigidbody", {type: "static", friction: 0.5, restitution: 0.5});

// set material, dimensions, and location
goldToken.model.material = this.goldMaterial.resource;  goldToken.setLocalScale(0.66, 0.15, 0.66);  goldToken.rigidbody.teleport(goldPosition);
                                
// sets name for programming reference
goldToken.name = "Gold_Token";
                                
// disable token spawning (as well as the tokenSpawner btm-left button) after token is placed
this.app.root.findByName("Gold_Button").script.goldButton.deSelect();   this.app.root.findByName("Spawner_Button").script.tokenSpawner.deSelect();

// end case 0
break;

tile spawning script:

// script to spawn the passive tile
Builder.prototype.passiveSpawn = function() {
    var ghost       = this.app.root.findByName("Ghost");
    var passiveTile = new pc.Entity();
    
    // set passiveTile's location to ghost's current location
    var passivePosition = new pc.Vec3();
    passivePosition.set(ghost.getPosition().x, ghost.getPosition().y, ghost.getPosition().z);
        
    // set passiveTile's rotation to ghost's current rotation
    var passiveRotation = ghost.getLocalRotation();
    
    // spawn passive tile and add it to the entity hierarchy 
    this.app.root.addChild(passiveTile);
    
    // add components (box etc)
    passiveTile.addComponent("model", {type: 'box',});
    passiveTile.addComponent("collision", {type: "box", halfExtents: (0.5, 0.01, 0.5)});
    passiveTile.addComponent("rigidbody", {type: "static", friction: 0.5, restitution: 0.5});

    // set material, dimensions, rotation, and location
    passiveTile.model.material = this.passiveMaterial.resource;  passiveTile.setLocalScale(1, 0.01, 1);     passiveTile.setLocalRotation(passiveRotation);  passiveTile.rigidbody.teleport(passivePosition, passiveRotation);
                                
    // sets name for programming reference
    passiveTile.name = "Passive_Tile";
    
    console.log("Passive tile: ", passiveTile);
};

Also, I have no idea how to “Query type property”, or what that even means.

Turns out I messed up the collision component, not the rigidbody component. All I had to do was declare a variable to hold the Vec3 coordinates for half extents ahead of time.

var hExtents = new pc.Vec3(0.5, 0.01, 0.5);
...
passiveTile.addComponent("collision", {type: "box", halfExtents: hExtents});