0

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.

Oldy
  • 5
  • 2
  • Ok i have a question do you want to lock you camera? – Tanay Mar 30 '22 at 17:22
  • @Tanay Yes I would like to lock the camera in its default position when camera is disabled (this works) but what seems to go wrong is when I enable the editor_camera, anything on the screen just disappears. – Oldy Mar 30 '22 at 19:37

2 Answers2

1

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.

pokepetter
  • 1,383
  • 5
  • 8
1

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()
Tanay
  • 561
  • 1
  • 3
  • 16