When I inherit from a class assigning SceneLocationView() sceneNode is nil

When I try to post a LocationAnnotations of a subclass respect to the one defining variable sceneLocationView, by way of:


sceneLocationView.addLocationNodeWithConfirmedLocation(locationNode: bannerAnnotationLocation)

When I enter in:

public func addLocationNodeWithConfirmedLocation(locationNode: LocationNode) {
        if locationNode.location == nil || locationNode.locationConfirmed == false {
            return
        }

        updatePositionAndScaleOfLocationNode(locationNode: locationNode, initialSetup: true, animated: true)

        locationNodes.append(locationNode)
        print(sceneNode?.description ?? "nil")
        self.sceneNode?.addChildNode(locationNode)
    }

I find sceneNode to nil, like if the effect of the renderer is lost when subclassing. I also tried to create a new variable in the subclass also assigning SceneLocationView(), but sceneNode remains nil. What to do to force it to assume a value?

I sort of fixed the issue by modifying addNode as follows:

func addNode(annotationLocation: ARCL.LocationAnnotationNode) {
        if let sceneNode=sceneLocationView.sceneNode {
            sceneLocationView.addLocationNodeWithConfirmedLocation(locationNode: annotationLocation, sceneNode: sceneNode)
        } else {
            let completion: ((SCNNode)->Void)={(sceneNode) in
                DispatchQueue.main.async {
                    print("sceneNode" + (sceneNode.description))
                    self.sceneLocationView.addLocationNodeWithConfirmedLocation(locationNode: annotationLocation, sceneNode:sceneNode)
                    sceneLocationView.focusItems(in: annotationLocation.frame)
                }
            }
            let nodeComposition = NamedSceneNode(sceneNodeCompletion: completion)
            nodeComposition.progress()
            print("count \(nodeComposition.counter)")
            if var viewController=UIApplication.topViewController() as? ViewControllerProtocol{
                if !viewController.nodeShowingCompletions.contains(nodeComposition){
                    viewController.nodeShowingCompletions.insert(
                        nodeComposition
                )
            }
            
        }
    }

With:

struct NamedSceneNode: Hashable{
    static func == (lhs: NamedSceneNode, rhs: NamedSceneNode) -> Bool {
        lhs.counter == rhs.counter
    }
    
    var sceneNodeCompletion: ((SCNNode)->Void)
    static var count: Int=0
    
    var counter: Int{
        return NamedSceneNode.count
    }
    func progress(){
        NamedSceneNode.count+=1
        print("counter ora: \(counter)")
    }
    
    func hash(into hasher: inout Hasher) {
        hasher.combine(counter)
    }
}

And then executing the completions in:

func sceneLocationViewDidUpdateLocationAndScaleOfLocationNode(sceneLocationView: SceneLocationView, locationNode: LocationNode) {
        guard let sceneNode=sceneLocationView.sceneNode else {
            return
        }
        print("updated element"+locationNode.description + "sceneNode: " + (sceneLocationView.sceneNode?.description ?? "nil"))
        
        for nodeCompletion in self.nodeShowingCompletions {
            nodeCompletion.sceneNodeCompletion(sceneNode)
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
                self.nodeShowingCompletions.remove(nodeCompletion)
            }
        }
    }

Of course recycling the same sceneNodes over and over again.

When I inherit from a class assigning SceneLocationView() sceneNode is nil
 
 
Q