A Neat Scaleform Hack

One of the things I’ve always hated about UnrealScript is that you can’t reference objects across packages. Take Java, for example – if you’ve got two classes that are in the same package (Classay and Classbee, let’s say), you can call any of Classbee’s functions or reference any of its variables from Classay, provided they are not private/protected. You don’t need to do any importing.

But in UnrealScript it’s like there’s a wall between classes. Let’s say you wanted to reference a UTGame function from UTPlayerController. You can’t just say UTGame.myFunction(). You have to set a UTGame variable, grab WorldInfo.Game, and point it to the current running game. This creates amazingly annoying problems when getting into Scaleform.

Recently, I wanted to reference a time-dependent variable from UTGame in my main menu (which is a GFxMoviePlayer). “Time-dependent” just means that the variable changes over time; in this case it’s zero at login, and some other value once UDK receives a message from the Internet. Because the time it takes to receive the message can vary wildly depending on the Internet connection, I couldn’t assume that the variable would be correct when the movie was initialized. Nor could I set a Tick() function to keep checking the variable, because that would slow UDK to a crawl.

If UnrealScript was anything like Java, the answer to this problem would be simple: once the variable changed, just call GFx_MainMenu.SetPlayerCount() from UTGame. As it was, I was stuck with a neat hack that took me about 30 minutes to figure out:

  1. From UTGame, trigger a remote Kismet event when the variable changes
  2. In Kismet, link the remote event to a “GFx Invoke ActionScript” on the main menu movie that invokes a function myFunction()
  3. In the main menu’s ActionScript, have a function myFunction() that does ExternalInterface.call(“myUDKFunction”)
  4. In the main menu’s UnrealScript, have a function myUDKFunction() that grabs the variable from UTGame and displays it

Yes, it’s a terrible hack…but as always, it works. If you know of the correct (in other words, not so hacky) way of doing it, please email me and I’ll credit you in a new post. For now, though, this will have to do.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s