Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Levels and sub-levels #87

Closed
sinokgr opened this issue Dec 14, 2016 · 7 comments
Closed

Levels and sub-levels #87

sinokgr opened this issue Dec 14, 2016 · 7 comments

Comments

@sinokgr
Copy link
Contributor

sinokgr commented Dec 14, 2016

Hi there,

Can you please add support to create levels and sub-levels?
I want if possible to be able to create sub-levels to my current level and add actors there.

Cheers,
Nick

@rdeioris
Copy link
Contributor

rdeioris commented Dec 17, 2016

Wow it was hard, i finally grasped how the whole level structure works. The support is pretty raw but should be a good base:

import unreal_engine as ue
from unreal_engine.classes import WorldFactory

factory =  WorldFactory()
new_Level = factory.factory_create_new('/Game/NewLevel001')

this will create a new level asset (well it is a world !)

You can access levels of a world with the new get_levels() function (it returns a list of levels)

To add a level to a world:

ue.add_level_to_world(world, '/Game/name_of_the_level_asset'[, persistent])

(set persistent as True, if you want your level to be always loaded)

Finally to move actors between levels:

ue.move_selected_actors_to_level(level)

well, this is annoying because it is the same api used in the editor, so it works only for selected actors.

Lucky enough we already have the selection api:

actor = world.actor_spawn(Actor)
ue.editor_select_actor(actor)
ue.move_selected_actors_to_level(level)

absolutely not the most handy api, but currently i do not see too much other solutions

@sinokgr
Copy link
Contributor Author

sinokgr commented Dec 19, 2016

Many thanks for all your efforts @rdeioris ! Sorry this gave you such a hard time!

The level creation bit works great! I'm having a few issues with part that moves the actors to the level though.
I couldn't find a function named move_selected_actors_to_level and the closest function I found was this , a function with the python name "move_actor_to_level". This function though requires two arguments and I can't figure out which.
Btw, would it be possible to have a version where you can pass the Actors without the need to select them - selecting is not the fastest approach most of the times?

Sample code I tried:

import unreal_engine as ue
from unreal_engine.classes import WorldFactory, StaticMeshActor

world = ue.get_editor_world()
new_Level = WorldFactory().factory_create_new('/Game/Levels/PyLevel')
ue.add_level_to_world(world, '/Game/Levels/PyLevel')

actor = world.actor_spawn(StaticMeshActor)
ue.editor_select_actor(actor)
#  This bit crashes
ue.move_actor_to_level(new_Level)

Returns:
TypeError: move_selected_actors_to_level() takes exactly 2 arguments (1 given)

PS. sorry if this sounds stupid, but what is the syntax to make the level persistent? Using ue.add_level_to_world(world, '/Game/Levels/PyLevel', False) or ue.add_level_to_world(world, '/Game/Levels/PyLevel', True) doesn't seem to make a difference - or I'm looking to wrong place.

@rdeioris
Copy link
Contributor

rdeioris commented Dec 19, 2016

Hi, i have fixed the function (both its name and the number of arguments), regarding level persistance take into account that the levels panel does not update when you add levels (i need to investigate how to refresh it). I am checking if i can avoid the selction part

@rdeioris rdeioris reopened this Dec 19, 2016
@sinokgr
Copy link
Contributor Author

sinokgr commented Dec 19, 2016

Awesome! Many thanks @rdeioris, I'll go try it now. Yeah, I've noticed that about the Levels window. I keep closing it and re-opening it for now.

@sinokgr
Copy link
Contributor Author

sinokgr commented Dec 19, 2016

Hm.. I know get an error saying:
ue.move_selected_actors_to_level(new_Level)
Exception: argument is not a ULevelStreaming

import unreal_engine as ue
from unreal_engine.classes import WorldFactory, StaticMeshActor

world = ue.get_editor_world()
new_Level = WorldFactory().factory_create_new('/Game/Levels/PyLevel')
ue.add_level_to_world(world, '/Game/Levels/PyLevel')

actor = world.actor_spawn(StaticMeshActor)
ue.editor_select_actor(actor)
ue.move_selected_actors_to_level(new_Level)

@sinokgr
Copy link
Contributor Author

sinokgr commented Jun 27, 2017

Hi @rdeioris , I'm bringing up this again.
I haven't tried to assign actors to a level this time and I haven't used it since my last post, but I tried to the a level by name, but it looks like something is not working in the levels. For example, I have these three levels that have different colors and names
image
but when I run the following script

import unreal_engine as ue
from unreal_engine.classes import WorldFactory

world = ue.get_editor_world()
levels = world.get_levels()
for level in levels:
	print ("--------------"  + level.get_name() + "--------------")
	print level.LevelColor

I'm getting

--------------PersistentLevel--------------
<unreal_engine.FLinearColor {'r': 1.0, 'g': 1.0, 'b': 1.0, 'a': 1.0}>
--------------PersistentLevel--------------
<unreal_engine.FLinearColor {'r': 1.0, 'g': 1.0, 'b': 1.0, 'a': 1.0}>
--------------PersistentLevel--------------
<unreal_engine.FLinearColor {'r': 1.0, 'g': 1.0, 'b': 1.0, 'a': 1.0}>

I'm guessing it finds the number of levels - as I'm getting three as well - but it doesn't iterate and it only returns the first one.

Can you please have a look?

@rdeioris
Copy link
Contributor

rdeioris commented Oct 1, 2017

The level api has been added and documented: https://github.com/20tab/UnrealEnginePython/blob/master/docs/Level_API.md

@rdeioris rdeioris closed this as completed Oct 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants