Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Removing renderer component in Update function

edited December 2017 in Codea Craft Posts: 65
I’am having trouble when I try to remove a renderer component of an entity, to make it invisible. However Codea just crashes instead of giving me an error.
Here is my project:
https://www.dropbox.com/s/tefbg1mk3wbkcuv/Tiny Rockets.zip?dl=0
It’s quite long but the part where everything fails is at the Quadtree class. Maybe you can help?
Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 6,831

    @GR00G0 I tried running your code, but I’m not sure what is supposed to be happening. If I comment out the local cam= line in setup, I can run the code and I see an object that I can rotate. It doesn’t crash, but I’m sure it’s not doing everything you want it to do.

  • Posts: 65
    @dave1707 You have to wait until the camera( you have to include camera library) falls close down and is close enough to the randomly generated mesh.
  • dave1707dave1707 Mod
    Posts: 6,831

    @GR00G0 I wonder if when you execute self.entity:remove(craft.renderer) it crashes because it doesn’t know what to remove. Like I said I’m not sure about everything you’re doing so that’s just a guess.

  • Posts: 65
    @dave1707 It worked if I just did it in the Quadtree:init() function. But what happend for you? Maybe it’s just a bug on my iPad
  • dave1707dave1707 Mod
    Posts: 6,831

    @GR00G0 Here is your code that I’m executing when it crashes. If I comment the line self.entity:remove(craft.renderer) it doesn’t crash. So what are you trying to remove with that line.

    function Quadtree:update(DeltaTime)
        if self.size > 64 and self.mode == "subdivide" then
            if self.camera.worldPosition:dist(self.entity.worldPosition) < self.size then
                self.entity:remove(Quad)
                print("2nd")
                print(self.entity)
                self.entity:remove(craft.renderer)
                print("success")
                self.mode = "subdivided"
            end
        end    
    end
    
  • edited December 2017 Posts: 65
    @dave1707 I am trying to make the entity invisible.
    Edit: And I can’t just set the model or material to nil.
  • dave1707dave1707 Mod
    Posts: 6,831

    @GR00G0 I’m not following your code very well. I can see that you’re trying to remove self.entity, but what is self.entity pointing to. If I print out self.entity, it just says entity, so I don’t know what self.entity is referring to.

  • dave1707dave1707 Mod
    Posts: 6,831

    @GR00G0 So far I figured out that self.entity is the mesh your creating in the class Quad. Is that true.

  • edited December 2017 Posts: 65
    @dave1707 Either I completely misunderstood how entities work or you didn’t understand my code. I am not removing the entity, and the entity isn’t the Quad class. The entity is the entity it is attached to and I am removing the renderer component from it.
    Edit: My problem is it works as long as remove it in the Quadtree:init() function but it doesnt work in the update function, and I have checked Its not because it’s trying to remove it twice. The code nlock there only get’s executed once.
  • dave1707dave1707 Mod
    Posts: 6,831

    @GR00G0 I’m not into Craft that much because I’m waiting for the final version along with better documentation. I don’t understant all of the adds along with the adds in the classes and so on. It’s hard to keep track of what’s where and what’s actually happening. Maybe if I wrote the code and I knew exactly what I was trying to do would help me understand it, but to look at someone else’s code isn’t helping. So I guess I’ll just leave it for someone who understands Craft more than I do help you.

  • Posts: 65
    @dave1707 The craft documentation isn’t 100% complete but about 95%. Also Im just trying to make a entity invisible if I get to close to it. Maybe you want to code something yourself to see ehat I mean.
  • dave1707dave1707 Mod
    Posts: 6,831

    @GR00G0 I posted code awhile ago showing that if you get inside an entity, it disappears. There’s still a lot I need to learn about Craft and I just need to play around with all of the adds and removes and other thing to get a grasp of how Craft actually works.

  • edited December 2017 Posts: 65
    @dave1707 Yeah Injust found out it’s a bug that @John has to fix. Removing craft.renderer or craft.camera crashes codea
    Edit: Neither does rigidbody
  • entity.active=false will make it invisible

  • Posts: 65
    @piinthesky but would’nt that also turn off it’s update function and it’s parent transform
  • @GR00G0 i guess it would

  • @GR00G0 while waiting for the bug fix, perhaps setting its size to zero, using entity.scale=vec3(0,0,0) might be a work around.

  • edited December 2017 Posts: 65
    @piinthesky That could work, but it would still be a rendered object. So I am currently just creating a child entity which I can destroy
Sign In or Register to comment.