Backgrounds¶
change_background() in unreal_engine_tools.py swaps the sky, lights and post-processing of the main map.
| Background | Looks like |
|---|---|
'white' |
A white studio, lit by a sun |
'white_no_bloom' |
White without glow |
'white_less_emissive' |
A softer white; Starcel's default in main.py |
'black' |
Black |
'stars' |
A star field |
'sky' |
A sky with time of day |
'sky_no_time' |
A sky with a fixed sun |
'custom_material' |
A sky sphere with a material of your own |
'image' |
A picture on the sky sphere: pass path= |
'video' |
A video on the sky sphere: pass path= |
'transparent' |
Hides the sky so a transparent window shows your desktop |
Pictures and video¶
change_background('image', path='C:/Users/me/Pictures/panorama.jpg')
change_background('video', path='C:/Users/me/Videos/loop.mp4')
The path must exist. Equirectangular (360°) pictures and videos look best.
Transparent window¶
from unreal_engine_tools import toggle_window_transparency
toggle_window_transparency() # on: the desktop shows wherever nothing is drawn
toggle_window_transparency() # off: back to the previous background
This only works in the standalone game or a packaged build, not in Play In Editor.
To run Starcel as your desktop wallpaper, see the window functions and the video there.
Cycling through backgrounds¶
from unreal_engine_tools import rotate_background
rotate_background() # next one in unreal_engine_tools.backgrounds
Make it the default¶
Change the change_background(...) line in main.py:
Note
change_background looks for the sky, fog, light and post-process actors in the main map. In other maps it logs no sky/fog/light/post-process actors in this map and does nothing.
In the tests¶
Copied from the code when this site is built. It switches through the backgrounds and then restores the one that was set.
From the tests: test_change_background (Content/Scripts/test_spawn.py:1963)
def test_change_background(base_y=0):
"""Switch through the backgrounds, then go back to the one that was set.
Each one is applied at once, so this mostly checks that every mode finds
its actors; watch the sky flicker while it runs."""
import unreal_engine_tools as tools
from unreal_engine_tools import change_background, find_actor
if find_actor('SkyLight5') is None:
return _skip('change_background', 'this map has no background actors')
before = tools._background_before_transparent
modes = [('white', 'file://'), ('black', 'file://'),
('white_no_bloom', 'file://'), ('stars', 'file://'),
('sky', 'file://'), ('sky_no_time', 'file://')]
picture = os.path.abspath(os.path.join(
ue.get_content_dir(), '..', 'Images', 'starball.png'))
if os.path.isfile(picture):
modes.append(('image', picture))
results = {}
try:
for background, path in modes:
t0, ok = time.monotonic(), None
try:
change_background(background, path=path)
if tools._background_before_transparent[0] == background:
ok = background
except Exception as e:
_log_exception(f'background_{background}', e)
results.update(_result(f'background_{background}', ok,
inputs={'path': path},
elapsed=time.monotonic() - t0))
finally:
change_background(*before)
_log(f' background restored to {before[0]}')
return results