1 (edited by grahf 2016-06-18 08:00:06)

Topic: Alternate Costumes [SOLUTION]

I wrote this code some time ago Because when my brother taught me how movesets and character models worked on UFE my first thought was" that should make easy to create characters with multiple costumes", but when he told me UFE hadn't implemented that I make the commitment to myself that I should do it for our Game Tzompantli. So I already did it some months ago, but did not have time to post it until now, here it is the way I made the alternate costumes work on UFE.


First

on CharacterInfo.cs just add

public GameObject alternateCharacterPrefab; 

after

public GameObject characterPrefab;

Now add

public bool alternativeCostume = false;

after

public string characterDescription;

Thats all on CharacterInfo.cs, now we can go to GlobalInfo.cs and do a minor change

add the variable

public ButtonPress altButton;

In the  InputOptions class.
Now for easy use we are going to give us access to those variables throught the Edition window, to make that happen we are going to change  CharacterEditorWindow.cs and add

characterInfo.alternateCharacterPrefab = (GameObject) EditorGUILayout.ObjectField("Character Alt Prefab:", characterInfo.alternateCharacterPrefab, typeof(UnityEngine.GameObject), true);

after

characterInfo.characterPrefab = (GameObject) EditorGUILayout.ObjectField("Character Prefab:", characterInfo.characterPrefab, typeof(UnityEngine.GameObject), true);

Now in GlobalEditorWindow.cs add

globalInfo.inputOptions.altButton = (ButtonPress) EditorGUILayout.EnumPopup("Alt Button:", globalInfo.inputOptions.altButton, enumStyle);
after this line
globalInfo.inputOptions.cancelButton = (ButtonPress) EditorGUILayout.EnumPopup("Cancel Button:", globalInfo.inputOptions.cancelButton, enumStyle);

after this if you go to the global editor window on Unity this new option will appear
http://sagapodcast.com/blog/wp-content/uploads/2016/06/IMG_0467.jpg

And in the character editor will look like this
http://sagapodcast.com/blog/wp-content/uploads/2016/06/IMG_0468.jpg

Now we can go to the last part of this simple tutorial and make the game chose the costume we want, as you can imagine, in the altButton option in the input options that  you now have in your global editor you must choose a button that when pressed will set the option to load the alternateCharacterPrefab when the variable alternativeCostume is true, so after you add an alternate character prefab to your character and choose the button you want to use to select the alternate costume function we will write the rest of the code.

Now in controlsScript.cs in the start function after

if (myInfo.characterPrefab == null) 
            Debug.LogError("Character prefab for "+ gameObject.name +" not found. Make sure you have selected a prefab character in the Character Editor");

Add these lines

        
//JUST A DEBUG FOR CHECKING HOW IS WORKING ALL
Debug.Log ("ControlScript,Player:"+playerNum+"Alternate Costume Value:" + myInfo.alternativeCostume);
        if (myInfo.alternativeCostume) {
            if (myInfo.alternateCharacterPrefab == null)
            {
                character = (GameObject)Instantiate (myInfo.characterPrefab);
                Debug.Log("Character prefab for "+ gameObject.name +"The Character Doesn't Have Alternate Costume. Make sure you have selected a prefab character in the Character Editor");
            }
            else
                character = (GameObject)Instantiate (myInfo.alternateCharacterPrefab);
        } else {
            character = (GameObject)Instantiate (myInfo.characterPrefab);
        }

As you can see, the code changes the default character loading behavior so if the alternativeCostume variable is true it will load the alternative prefab we added to the character info, in any case there were an error and the character doesn't have a alternate costume, the game will load the regular one, so you  don't have to give al characters an alternative costume if you don't want.

Now in CharacterSelectionScreen.cs let's add this lines to the OnCharacterSelectionAllowed

after

if (character != null && character.selectionSound != null) UFE.PlaySound(character.selectionSound);

add this

                    if((player == 1 && this.p1AltCustom==true) || (player == 2 && this.p2AltCustom==true))
                    { 
                        character.alternativeCostume=true;
                    }
                    else
                    {
                        character.alternativeCostume=false;
                    }
                                        //I really like to send debugs  
                    Debug.Log("Character Select,Player "+player+" alternate:"+character.alternativeCostume);

and after

protected int p2HoverIndex = 0;

You must add

protected bool p1AltCustom=false;
protected bool p2AltCustom=false;

The last bit of code is to be able to put in true or false the p1AltCustom or p2AltCustom, so in DefaultCharacterSelectionScreen.cs on the doFixedUpdate function after:

base.DoFixedUpdate();

just add:

if(p1InputController.GetButtonDown(UFE.config.inputOptions.altButton)){

            this.p1AltCustom =!(this.p1AltCustom);
            Debug.Log("Boton Alterno player 1:"+this.p1AltCustom);
            //this.TrySelectCharacter(this.p1HoverIndex, 1);
            
        }
        if(p2InputController.GetButtonDown(UFE.config.inputOptions.altButton)){
            this.p2AltCustom =!(this.p2AltCustom);
            Debug.Log("Boton Alterno player 2:"+this.p2AltCustom);
            //this.TrySelectCharacter(this.p1HoverIndex, 1);
            
        }

So, that's all, you now can make alternate Costumes for your characters in the way the first Soul Blade or Tekken Worked, some warnings, I never added a little window or something on the character selection screen so it show the player if he/she es choosing the regular or alternate costume, I have had no time for it yet, if I make it I will add it to this post.

Second, I know and figured out that if we could change the  alternateCharacterPrefab and characterPrefab to merge them in one characterPrefab[] (an array) and make some modifications to this code we can simply have infinity and variable alternate costumes for any character, like in Dead or Alive where the female characters have like 15 costumes and male characters have only 2, but I'll try it for the next game we make but if anyone wants to give a try just post it so everyone here can use it.

Last, the characters need to have the same bone structure, so the animations can run correctly, also you can add functionality so characters on alternate costumes can perform an alternate fighting intro animation, but I'm just talking nonsense.

Thank you and I hope anyone can use this options and doubts and complain are accepted by DM or twitter @seekerofpower

I only have this video from when I finished the script
https://www.facebook.com/seekerofpower/ … 8122777617

But I will ask mi brother if he can upload to youtube one nicer looking, sorry for my english

Share

Thumbs up +8 Thumbs down

Re: Alternate Costumes [SOLUTION]

in the default selection screen i dont see the

bool p2AxisDown =
            p2InputController.GetButtonDown(p2InputController.horizontalAxis) ||
            p2InputController.GetButtonDown(p2InputController.verticalAxis);

Share

Thumbs up Thumbs down

Re: Alternate Costumes [SOLUTION]

This is awesome! And something I'll really need for my game. I assume you have the source version and can modify this at will...

You also have to make sure the player CANNOT choose the alternate like in DOA5

Re: Alternate Costumes [SOLUTION]

diesonblack22 wrote:

in the default selection screen i dont see the

bool p2AxisDown =
            p2InputController.GetButtonDown(p2InputController.horizontalAxis) ||
            p2InputController.GetButtonDown(p2InputController.verticalAxis);


Yes, I just remembered that for some reason we've been unable to update our game to the news libraries of UFE, in the new version that code doesn't exist, I just Downloaded the new version of UFE and edited the post to reflect this, sorry

Share

Thumbs up Thumbs down

5 (edited by Meractus 2016-07-22 15:50:47)

Re: Alternate Costumes [SOLUTION]

Hello, I'm trying to approach your solution with a few different tweaks but got stuck in the same problem as this: http://www.ufe3d.com/forum/viewtopic.php?pid=3949. for both mecanim and legacy characters.

I reinstalled UFE in a new project following the tutorial and created a stance changing move for both mike and kyle and the problem persists. I have asked for help there as well, but since it's an old thread I don't know if I'll get help there.

Share

Thumbs up Thumbs down

Re: Alternate Costumes [SOLUTION]

Meractus wrote:

Hello, I'm trying to approach your solution with a few different tweaks but got stuck in the same problem as this: http://www.ufe3d.com/forum/viewtopic.php?pid=3949. for both mecanim and legacy characters.

I reinstalled UFE in a new project following the tutorial and created a stance changing move for both mike and kyle and the problem persists. I have asked for help there as well, but since it's an old thread I don't know if I'll get help there.

MMmm... wouldn't know, we use legacy animations and rigs... should take a look with a default character.

Me encontraste en un negro camino como un peregrino sin rumbo ni fe, pero la luz de tus ojos divinos cambió mi suerte por dicha y placer.

Re: Alternate Costumes [SOLUTION]

grahf wrote:

I wrote this code some time ago Because when my brother taught me how movesets and character models worked on UFE my first thought was" that should make easy to create characters with multiple costumes", but when he told me UFE hadn't implemented that I make the commitment to myself that I should do it for our Game Tzompantli. So I already did it some months ago, but did not have time to post it until now, here it is the way I made the alternate costumes work on UFE.


First

on CharacterInfo.cs just add

public GameObject alternateCharacterPrefab; 

after

public GameObject characterPrefab;

Now add

public bool alternativeCostume = false;

after

public string characterDescription;

Thats all on CharacterInfo.cs, now we can go to GlobalInfo.cs and do a minor change

add the variable

public ButtonPress altButton;

In the  InputOptions class.
Now for easy use we are going to give us access to those variables throught the Edition window, to make that happen we are going to change  CharacterEditorWindow.cs and add

characterInfo.alternateCharacterPrefab = (GameObject) EditorGUILayout.ObjectField("Character Alt Prefab:", characterInfo.alternateCharacterPrefab, typeof(UnityEngine.GameObject), true);

after

characterInfo.characterPrefab = (GameObject) EditorGUILayout.ObjectField("Character Prefab:", characterInfo.characterPrefab, typeof(UnityEngine.GameObject), true);

Now in GlobalEditorWindow.cs add

globalInfo.inputOptions.altButton = (ButtonPress) EditorGUILayout.EnumPopup("Alt Button:", globalInfo.inputOptions.altButton, enumStyle);
after this line
globalInfo.inputOptions.cancelButton = (ButtonPress) EditorGUILayout.EnumPopup("Cancel Button:", globalInfo.inputOptions.cancelButton, enumStyle);

after this if you go to the global editor window on Unity this new option will appear
http://sagapodcast.com/blog/wp-content/uploads/2016/06/IMG_0467.jpg

And in the character editor will look like this
http://sagapodcast.com/blog/wp-content/uploads/2016/06/IMG_0468.jpg

Now we can go to the last part of this simple tutorial and make the game chose the costume we want, as you can imagine, in the altButton option in the input options that  you now have in your global editor you must choose a button that when pressed will set the option to load the alternateCharacterPrefab when the variable alternativeCostume is true, so after you add an alternate character prefab to your character and choose the button you want to use to select the alternate costume function we will write the rest of the code.

Now in controlsScript.cs in the start function after

if (myInfo.characterPrefab == null) 
            Debug.LogError("Character prefab for "+ gameObject.name +" not found. Make sure you have selected a prefab character in the Character Editor");

Add these lines

        
//JUST A DEBUG FOR CHECKING HOW IS WORKING ALL
Debug.Log ("ControlScript,Player:"+playerNum+"Alternate Costume Value:" + myInfo.alternativeCostume);
        if (myInfo.alternativeCostume) {
            if (myInfo.alternateCharacterPrefab == null)
            {
                character = (GameObject)Instantiate (myInfo.characterPrefab);
                Debug.Log("Character prefab for "+ gameObject.name +"The Character Doesn't Have Alternate Costume. Make sure you have selected a prefab character in the Character Editor");
            }
            else
                character = (GameObject)Instantiate (myInfo.alternateCharacterPrefab);
        } else {
            character = (GameObject)Instantiate (myInfo.characterPrefab);
        }

As you can see, the code changes the default character loading behavior so if the alternativeCostume variable is true it will load the alternative prefab we added to the character info, in any case there were an error and the character doesn't have a alternate costume, the game will load the regular one, so you  don't have to give al characters an alternative costume if you don't want.

Now in CharacterSelectionScreen.cs let's add this lines to the OnCharacterSelectionAllowed

after

if (character != null && character.selectionSound != null) UFE.PlaySound(character.selectionSound);

add this

                    if((player == 1 && this.p1AltCustom==true) || (player == 2 && this.p2AltCustom==true))
                    { 
                        character.alternativeCostume=true;
                    }
                    else
                    {
                        character.alternativeCostume=false;
                    }
                                        //I really like to send debugs  
                    Debug.Log("Character Select,Player "+player+" alternate:"+character.alternativeCostume);

and after

protected int p2HoverIndex = 0;

You must add

protected bool p1AltCustom=false;
protected bool p2AltCustom=false;

The last bit of code is to be able to put in true or false the p1AltCustom or p2AltCustom, so in DefaultCharacterSelectionScreen.cs on the doFixedUpdate function after:

base.DoFixedUpdate();

just add:

if(p1InputController.GetButtonDown(UFE.config.inputOptions.altButton)){

            this.p1AltCustom =!(this.p1AltCustom);
            Debug.Log("Boton Alterno player 1:"+this.p1AltCustom);
            //this.TrySelectCharacter(this.p1HoverIndex, 1);
            
        }
        if(p2InputController.GetButtonDown(UFE.config.inputOptions.altButton)){
            this.p2AltCustom =!(this.p2AltCustom);
            Debug.Log("Boton Alterno player 2:"+this.p2AltCustom);
            //this.TrySelectCharacter(this.p1HoverIndex, 1);
            
        }

So, that's all, you now can make alternate Costumes for your characters in the way the first Soul Blade or Tekken Worked, some warnings, I never added a little window or something on the character selection screen so it show the player if he/she es choosing the regular or alternate costume, I have had no time for it yet, if I make it I will add it to this post.

Second, I know and figured out that if we could change the  alternateCharacterPrefab and characterPrefab to merge them in one characterPrefab[] (an array) and make some modifications to this code we can simply have infinity and variable alternate costumes for any character, like in Dead or Alive where the female characters have like 15 costumes and male characters have only 2, but I'll try it for the next game we make but if anyone wants to give a try just post it so everyone here can use it.

Last, the characters need to have the same bone structure, so the animations can run correctly, also you can add functionality so characters on alternate costumes can perform an alternate fighting intro animation, but I'm just talking nonsense.

Thank you and I hope anyone can use this options and doubts and complain are accepted by DM or twitter @seekerofpower

I only have this video from when I finished the script
https://www.facebook.com/seekerofpower/ … 8122777617

But I will ask mi brother if he can upload to youtube one nicer looking, sorry for my english

I don't have the time to try this out right now, but from the looks of it, excellent work!

Share

Thumbs up Thumbs down

Re: Alternate Costumes [SOLUTION]

I wonder if this would work on the stage select such as alternative version of stages. Example: Sunny or Rainy.

Re: Alternate Costumes [SOLUTION]

This works for me until I get to the last step.  I get errors saying that p1InputController and p2InputController do not exist in the current context.

Share

Thumbs up Thumbs down

10 (edited by acidfmhq 2017-07-10 10:45:55)

Re: Alternate Costumes [SOLUTION]

Sorry to resurrect this year old post but the reason why the last part of code doesn't work he forgot to set the variables for the InputController.

Right under

base.DoFixedUpdate(); 

Paste this

 AbstractInputController p1InputController = UFE.GetPlayer1Controller();
 AbstractInputController p2InputController = UFE.GetPlayer2Controller();

Then paste this

if(p1InputController.GetButtonDown(UFE.config.inputOptions.altButton)){

            this.p1AltCustom =!(this.p1AltCustom);
            Debug.Log("Boton Alterno player 1:"+this.p1AltCustom);
            //this.TrySelectCharacter(this.p1HoverIndex, 1);
            
        }
        if(p2InputController.GetButtonDown(UFE.config.inputOptions.altButton)){
            this.p2AltCustom =!(this.p2AltCustom);
            Debug.Log("Boton Alterno player 2:"+this.p2AltCustom);
            //this.TrySelectCharacter(this.p1HoverIndex, 1);
            
        }

Then it should work

Terrordrome Reign of the Legends Out now on Steam!!
https://store.steampowered.com/app/1291 … e_Legends/
Terrordrome Project Manager

Re: Alternate Costumes [SOLUTION]

Hi,

in the GlobalEditorWindow.cs:
when I added globalInfo.inputOptions.altButton = (ButtonPress) EditorGUILayout.EnumPopup("Alt Button:", globalInfo.inputOptions.altButton, enumStyle);

after this line
globalInfo.inputOptions.cancelButton = (ButtonPress) EditorGUILayout.EnumPopup("Cancel Button:", globalInfo.inputOptions.cancelButton, enumStyle);


I received this error:
Assets\UFE\Engine\Editor\GlobalEditorWindow.cs(1422,31): error CS1061: 'InputOptions' does not contain a definition for 'altButton' and no accessible extension method 'altButton' accepting a first argument of type 'InputOptions' could be found (are you missing a using directive or an assembly reference?)

All I did was copy and past. Did I do something wrong?

Share

Thumbs up Thumbs down

Re: Alternate Costumes [SOLUTION]

Hello,
I'm a little rusty with this old code, but by error it seems that you didin't add the altButton variable in the inputOptions class in the globalInfo.cs file.

It's the fifth code in the post.

I hope that's the reason for your error.

If you have any other issue just tell me.

Also, this code is for UFE 1.x The 2.x version needs some corrections, I dont know if I wrote a post about it too.

Share

Thumbs up +1 Thumbs down

13 (edited by nusaw316 2022-02-28 18:01:09)

Re: Alternate Costumes [SOLUTION]

grahf,

Thank you,


I'm doing some testing on the final step in UFE2 Source. I will update you when I find a solution.

Share

Thumbs up Thumbs down