Download

Getting LightMap Override Value

I’ve just started playing around with Unreal, and I have a couple of questions that I’m finding hard to google. My background is within 3D, but this is the first time playing around with a game engine, so please bear with me :slight_smile:

I’ve exported my 3D model into a scene within UE, and I’ve adjusted the LightMap-resolution on all of my objects. But very often when I do a re-import, the program shuts down, and I have to set the LightMap-resolution on the objects manually. I figured I could just create a script that retrieves all of the LightMap-resolution values and print them, and then use these outputs to automatically set the resolution-values with a script.

I haven’t been able to find a lot of info when googling this, so I was wondering if anyone here could help? Is this even possible? Or are there any better ways of doing this?

Morning,
I have been trying to do something similar, changing the “source light map index” property.
I tweaked my existing code to attempt what your trying to do, maybe you will find it useful or a good start?
Cheers,
Scott

import unreal as ue

def get_only_type(_ls, TYPE):
ar = ]

for i in _ls:
# horrible way to compare types... so embarrassed
if str(type(i)) == TYPE:
ar.append(i)
else:
# print '	NOT TYPE: {0} != {1}'.format(i,TYPE)
pass

return ar

def ue_import_texture_test():
_ls_selected = list(ue.GlobalEditorUtilityBase.get_default_object().get_selected_assets())
_ls_selected = get_only_type(_ls_selected, "<type 'StaticMesh'>")

for i in _ls_selected:
print "Get: light_map_resolution {0}" .format(i.get_editor_property("light_map_resolution"))
print "Set: light_map_resolution {0}" .format(i.set_editor_property("light_map_resolution", 1024))
print "Final: light_map_resolution {0}" .format(i.get_editor_property("light_map_resolution"))
print i.get_components()

print'ls len: {0}'.format(len(_ls_selected))


def main():
ue_import_texture_test()


main()

Thank you good sir, much appreciated :slight_smile:

Thank you, that was very helpful :slight_smile:

Here’s what I ended up with, if anyone is interested:


# LOAD THE CURRENT LIGHTMAP RESOLUTION
# Create variables for the object-names and lightmap-values
objNames = ]
objLightMap = ]
# Collect all assets
allProjectAssets = unreal.AssetRegistryHelpers.get_asset_registry().get_all_assets()
allProjectMeshes = [x.get_asset() for x in allProjectAssets if x.asset_class == 'StaticMesh' and x.object_path.__str__().startswith('/Game/Meshes')]
# Collect object-names and lightmap-values
for currActor in allProjectMeshes:
currActorName = currActor.get_name()
currActorLightMap = currActor.get_editor_property("light_map_resolution")
unreal.log("Actor: {} - LightMap: {}".format(currActorName, currActorLightMap))
objNames.append(currActorName)
objLightMap.append(currActorLightMap)

# APPLY THE COPIED LIGHTMAP RESOLUTION
# Collect all assets
allProjectAssets = unreal.AssetRegistryHelpers.get_asset_registry().get_all_assets()
allProjectMeshes = [x.get_asset() for x in allProjectAssets if x.asset_class == 'StaticMesh' and x.object_path.__str__().startswith('/Game/Meshes')]
# Apply lightmap-values to all matching object-names
for currActor in allProjectMeshes:
currActorName = currActor.get_name()
if currActorName in objNames:
currActor.set_editor_property("light_map_resolution", objLightMap[objNames.index(currActorName)])
objLightMap[objNames.index(currActorName)]