Oldy
Oldy

Reputation: 5

Ursina EditorCamera() toggle

this is the code I have used to toggle between having an EditorCamera in Ursina and turning it off:

from ursina import *
app = Ursina()
def input(key):
    if key == 'd':
        editor_camera.enabled = False
    if key == 'e':
        editor_camera.enabled = True

editor_camera = EditorCamera(enabled = False)

cube = Entity(model = "cube", texture = "brick") # just to see if it works


app.run()

When applied on its own like this, it works fine but when I apply the same logic to a much larger project, when enabling the camera (press e) everything just disappears and when I disable the camera (press d), it all reappears. Is there something I'm missing? Any help is appreciated.

Upvotes: 0

Views: 1109

Answers (2)

Tanay
Tanay

Reputation: 661

After @pokepetter's answer, I figured out a new solution, just replace your code with this one:

from ursina import *
app = Ursina()

def input(key):
    if key == 'd':
        editor_camera.ignore = True

    if key == 'e':
        editor_camera.ignore = False


editor_camera = EditorCamera()
cube = Entity(model = "cube", texture = "brick")
app.run()

Upvotes: 1

pokepetter
pokepetter

Reputation: 1489

From editor_camera.py:

def on_disable(self):
    camera.editor_position = camera.position
    camera.parent = camera.org_parent
    camera.position = camera.org_position
    camera.rotation = camera.org_rotation

So when you disable it, it will put the camera back to it's original position, which can be useful when making, you know, an editor.

If you simply want to stop the editor camera's code from running, I recommend setting editor_camera.ignore = True and update and input code will stop running, but on_disable won't get called. Alternatively you could do editor_camera.on_disable = None or just reset the position and rotation manually.

Upvotes: 1

Related Questions