| Home Page | Recent Changes

Embedding Code

Since Map Files are simply Unreal packages, they can contain all sorts of different resources in addition to geometry and Texture (UT)s. That includes UnrealScript code. Rather than including a bunch of small .u files with your map distribution, embed their code into your Map Files. Apart from being neater, that'll make a much more professional appearance than a cluttered .zip file.

Don't embed code without permission. (That's clear, but unfortunately not to everyone.) Be sure that the code's author is content with having his/her code embedded in maps. Besides, embedding code makes only sense for small code packages, and if being able to do a centralized update of the code package is not an issue.

Creating Code in MyLevel

You can create new classes in UnrealEd and store them directly into MyLevel. You might want to do this if:

See Create A Subclass for instructions.

The usual pitfalls of creating code in UnrealEd apply: Can't delete classes, can't rename classes, can't change a superclass, UnrealEd crashes when you change the property declarations of a class that is used in the map. If you're simply pasting a script (a custom one from this site for example), that's not a problem though.

Importing Code into MyLevel

...from a .u file

If you have a pre-existing .u file that you want to import in MyLevel, do it as follows:

  1. Make sure that you're not already using that .u file externally in your map; in other words, make the .u file import the first step of using the actors defined in that .u file. If you already have added actors from that .u file in your map, cut them into the clipboard, save your map, and close UnrealEd.
  2. Make sure that the .u package you're about to import isn't automatically loaded when UnrealEd starts. Check the EditPackages lines in UnrealTournament.ini and delete any line pointing to that .u package if necessary (then restart UnrealEd). Also, place the .u file you would like to import into the \UnrealTournament\System directory.
  3. Do UnrealEd Main Menu → View → Log to open the [log window]? or click the button on the Console Bar. At the prompt, enter:

     obj load file=whatever.u package=MyLevel

    (substitute "whatever" by the name of the package you want to import, of course). If everything works out, you'll see some log entries along the lines of "New file, existing package." If you made a typo in the file name, UnrealEd crashes (courtesy of the UnrealEd Goblin).

  4. If you previously had cut/removed existing actors from that package from your map, paste/re-add them.
  5. Do a full rebuild, then save.

Notes: After importing a package in this way, the actor browser in UnrealEd 2 will not show any imported actors that are direct descendants of actor (and possibly some others deeper in the tree too) unless you first deselect then reselect the Show Actor Classes Only checkbox to force a reload of the tree.

To get imported music to show up in the music browser, click the docked/undocked button and your imported music file will show up.

Only actors that are referenced in the map and their parent classes get saved in MyLevel with the map so if you have actors that only get spawned in runtime and are in the package you just imported you need to add an example in your map somewhere out of sight so they get stored in MyLevel and can be spawned properly in game. This would apply to projectiles in custom weapon types etc.

Be sure to test your new map on a virgin install of Unreal Tournament that has none of the packages you've imported classes from in it. Otherwise it's dead easy for a reference to something that isn't sucessfully stored in MyLevel to get missed and what you thought would be a triumphant release of your latest project gets off to a bad start when your map crashes the game on load thanks to missing resources...

...from another map file

Some authors distribute their scripts already embedded in Map Files. To use them (the "with permission" clause above applies, of course), do the following:

  1. Restart UnrealEd. (Always a good idea before working with MyLevel.)
  2. Open the map file that contains the code you want to import.
  3. Without closing UnrealEd, open your own map file you want to import the code into.

UnrealEd doesn't remove the code classes from the first map file you opened when you open the second one; if you use any of those classes in your own map, they will automatically be saved along with your map.

Tip: If you're planning to distribute your own code via the second method (which is handy because it forces mappers to embed the code into their maps rather than bundling an .u file), be sure that you only place code in your distribution map's MyLevel. UnrealEd is prone to crashing if there are, for instance, Textures left from a previously loaded map file in MyLevel when the user loads his/her own map after yours.

Updating Code in MyLevel

Sometimes you might have to update the code of components embedded in MyLevel.

  1. Open the map the code is embedded in.
  2. In the actor browser, browse to the embedded actor class and double-click it. A script editor window with the component's source code opens.
  3. Select all of the old source code in the script editor window and delete it.
  4. Copy all of the new source code up to, but not including the defaultproperties section (if there is one).
  5. Paste the copied source code into the script editor window (click into the empty window and press Ctrl+V).
  6. Select ToolsCompile Changed from the script editor's menu. After a brief processing delay, the script editor's status bar says something along the lines of "Success: Compiled xx line(s), xx statement(s)." (You might have to move the script editor window up a bit in order to see its status bar.)
  7. Save your map.

Related Topics

Discussion

SabbathCat: Models can be imported too!! I've not tried with anything more complex than simple decorations, but you can definitely do it. :) So cool, no worries about "version mismatch". I had a bunch of flagbase meshes I was always including with my maps, but keeping track of which version was out with which map can be difficult. What a great solution to package everything into the map. :)

Foxpaw: Yes, you should be able to package anything into a map including code, textures, sounds, models, static meshes, and prefabs. Like it says above a map is just a package like any other. In theory you could probrably even package multiple maps into a package, but you might need a third party application to do that and I'm not sure how you would go about loading the different maps.

Wormbo: Loading a map into a map? Should be possible through OBJ LOAD File=..\Maps\TheMap.ut2 Package=myLevel, but I doubt this works without crashing or rendering the existing map useless.

Mychaeel: The map loading code probably either assumes that all objects in a map file belong to the same map, or it always just loads all those objects connected to the first LevelInfo object it finds in the map file. While it should be possible to store two maps in the same Unreal package without problems, I strongly suppose it's not actually possible to use those packages without some native code changes.

SabbathCat: There's a pitfall.. I recently embedded a bunch of mesh files and one music file, all well and good, the map plays and runs without a glitch, but now when I open it in the editor, I just get a blank screen. :(

It may perhaps be the music thing, The imported music didn't show up until I loaded another music package, I could then the MyLevel.musicname track to apply in the level properties.

Is it best to do all your importing once the map is near complete?

ah well, on the up side of course you could consider this an excellent way to safeguard maps from being re-built or plundered without permission. :)

Maybe I should try impoting the map into a new map?

inio: blank viewports or one big white screen? if it's the later, do viewports→configure→ok

Wormbo: Music package? You're talking about UT, right? Blank screen problem in UEd is described on UnrealEd viewport.

SabbathCat: Er, no. :) A blank screen as in a totally empty map. I stuck back all the .u files I'd removed from the system directory and the .umx in the music directory post-import, and it opened again.

Ch3z: This is very helpful. Answered my question. A related topics section could help too. I now wonder how to call the mutator I embedded into action. A link in the related topics secton to a page that explained that would be perfect.

Foxpaw: I'm not sure if there's a wiki page on it or not, but if you want to embed a mutator you will probrably need to also make a custom actor to load the mutator. You can then embed the actor and place one on your map. That actor can load the mutator in it's postbeginplay function and then destroy itself once the mutator is loaded.

Ch3z: Thx Fox. And I knew I had seen more on this somewhere. Finally came across it again and addeed "Related" section.

Jimbo: I've imported a vertex mesh into mylevel in UT2003 using the aforementioned procedure and it works quite fine. Strangely however, the mesh is not visible over netplay to the client who connects to me. I still see the mesh but he doesn't. If he disconnects from me and runs his own server or just plays an instant action match, the mesh is visible. Anyone have any ideas what might be causing this problem?

Kamek: Can OGG files be embedded into maps?

Wormbo: No. They are no package files themselves and UT200x doesn't provide any option to import generic binary files into packages.


Category Mapping
Category Tutorial

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

FAQs

Help Desk

Mapping Topics

Mapping Lessons

UnrealEd Interface

UnrealScript Topics

UnrealScript Lessons

Making Mods

Class Tree

Modeling Topics

Chongqing Page

Log In