8

Using Realitykit, trying to change the material of moon Entity to a custom .jpg and then tapping the screen to spawn that object based off hitTest. Nothing shows up when I tap and getting the following error in debug: [Collision] Bad paramater (SphereRadius), value = 0.000000, passed to shape creation.

import UIKit
import RealityKit

class ViewController: UIViewController {

    @IBOutlet var arView: ARView!

    override func viewDidLoad() {
        super.viewDidLoad()

    }

        override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
            if let touchLocation = touches.first?.location(in: arView){
                let hitTest = arView.hitTest(touchLocation)
                if let hitResult = hitTest.first {
                    addObject(at: hitResult)
                }
            }
        }

        func addObject(at hitResult: CollisionCastHit) {
            let moonAnchor = try! Galaxy.loadWorld()
            let moon = moonAnchor.moon! as! ModelEntity
            var material = SimpleMaterial()
            material.baseColor = try! MaterialColorParameter.texture(TextureResource.load(named: "8k_moon.jpg"))
            moon.model?.materials = [material]
            moon.position = SIMD3(x: hitResult.position.x, y: hitResult.position.y, z: hitResult.position.z)
            arView.scene.addAnchor(moonAnchor)
        }

}
Lawlitrix
  • 81
  • 3
  • Can you provide more of your code? Based on the error I would think the issue is with the model not the texture. – iicaptain Jun 06 '20 at 17:26
  • @iicaptain Hey, thanks for replying. Just updated the code, which contains everything in the ViewController. Haven't touched any of the other Realitykit files. The moon entity I'm trying to load is from a RCProject file from Reality Composer. – Lawlitrix Jun 06 '20 at 23:11
  • 2
    I'm having exactly the same problem. It does not seem to be model related as I tried a few different models from different sources. – vfxdev Jul 03 '20 at 13:45

2 Answers2

1

I have encountered that error when trying to hitTest an entity without a CollisionComponent. Hit testing requires a CollisionComponent on target entities:

"The method ignores entities that lack a CollisionComponent." https://developer.apple.com/documentation/realitykit/arview/3243230-hittest

If this is the problem, and since your model is being loaded from Reality Composer, a solution would be to check the "Participates" box in the Physics section of RC.

Rick Free
  • 143
  • 1
  • 10
  • This is correct. And the error seems to be an internal RealityKit error. I'm getting it anywhere I tap. And lol, there's a misspelling there... paramater :)) – Danylo Kurylo Aug 29 '20 at 01:30
  • I get this error every time I call hitTest/entity/entities if there are any elements on screen or even if there are not! – YanivH Aug 31 '20 at 18:22
  • I get the same error even if there are no entities on the screen :-/ – Chris Dec 06 '20 at 21:32
  • I get this error on my iPhone XS, but not on my iPhone 6s Plus – Chris Dec 06 '20 at 21:48
0

In my case I forgot to initialize my anchor in hitResult:

let anchor = AnchorEntity(world: transform)
sɐunıɔןɐqɐp
  • 3,332
  • 15
  • 36
  • 40
Azade Rahmati
  • 135
  • 1
  • 5