| Home Page | Recent Changes | Preferences

DynaMusic

DynaMusic optional music for mappers !

Usage:

  1. Follow the directions for Embedding Code
  2. Place dynamusic actor on your map
  3. Right click on it to bring up properties
  4. Select the DynaMusic/LoadSong property and type in the song "PackageName.SongName" you want to be optional
  5. Right click on empty part of map to bring up the level properties
  6. Change audio/song to one of the standard UT music packages ( this package won't be optional )

The way it works:

  1. When the player connects DynaMusic attempts to load music package
  2. If it's successful it overides the maps default music (as defined in Level properties), with the optional music

//=============================================================================
// DynaMusic.       By Dirk Fist  with all do credit to the people of the Wiki 
//=============================================================================
class DynaMusic expands Actor;

var() string LoadSong;
var music song;
var PlayerPawn MusicPlayer;
var bool bMusicStarted;
var int started;

replication
{   // Variables which will cause replication to all (relevant) clients
    reliable if ( Role == ROLE_Authority )
        started,LoadSong;
}

function PreBeginPlay()           // executed on server
{
    started +=1;                  // force replication
    Super.PreBeginPlay();
}

auto simulated state startup
{
Begin:
    log("Started",'Dynamusic');
    song = music(DynamicLoadObject( LoadSong, class'Music',True));
    if (song!=None)
    {   // we got a song lets find player
        log(string(song.Class),'Dynamusic');

        foreach AllActors(class 'PlayerPawn', MusicPlayer)
            if (Viewport(MusicPlayer.Player) != None)  break; 
        if (MusicPlayer != None)
        {   // We got player lets play 
            MusicPlayer.ClientSetMusic( song, Level.SongSection, Level.CdTrack, MTRAN_Fade );    
            log(MusicPlayer.PlayerReplicationInfo.PlayerName,'Dynamusic');        
    }   }
}

defaultproperties
{
    bAlwaysRelevant=True
    RemoteRole=ROLE_SimulatedProxy
}

Dirk Fist: My First Wiki Project :)

Dirk Fist: Can I upload a .u or .unr file ?

Dirk Fist: Found some info on making the packages optional http://unreal.epicgames.com/UTMagic.html#PackageFlags

Dirk Fist: If any one knows another way I'd be glad to hear it? Since I don't want to cause version conflicts for maps that use non-optional umx(ogg?) version of the file, Since this is a mapping component and many mappers will probably borrow music from other maps.

Wormbo: UT200x's OGG files aren't Unreal packages and won't be sent from the server. (They are already optional.) In UT non-optional music packages are sent by the server because the map's dependancy on the music package automatically makes it a ServerPackage. BTW: It's better to put the music loading code in PostBeginPlay() and skip the state code alltogether. Make the whole thing a non-replicated bStatic and/or bNoDelete actor and you won't need to replicate anything because the property LoadSong is already set by the mapper and the actor exists on all clients already.

Dirk Fist: Thanks for the suggestions. I tried alot of stuff before getting it to work. I had alot of trouble with the actor not existing until the first replication event. Also for some reason if LoadSong is different from class default then it needs to be replicated to work with pure6E. And although the definition for DynamicLoadObject may not be latent it seems to behave that way for music file's that are very large (Check past revisions of Dirk Fist )

Dirk Fist: Did'nt mean to sound so defensive. Could someone explain the proper use of bStatic, bNoDelete, and Non-replicated actors link it from Chain of Events When Spawning Actors, Netcode Idioms, and Replication.


Category Class (UT)
Category Custom Class

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

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