0
\$\begingroup\$

My room is bigger than my UMA character so on spawn my character looks tiny. I have found this link: http://answers.unity3d.com/questions/988134/uma-how-to-increase-npc-avatar-scale.html

but everywhere I put my code, it does not change my avatars features. Here is my code:

using UnityEngine;
using System.Collections;
using UMA;


public class UMACreator1 : MonoBehaviour {
    public UMAGeneratorBase generator;
    public SlotLibrary slotLibrary;
    public OverlayLibrary overlayLibrary;
    public RaceLibrary raceLibrary;
    public RuntimeAnimatorController animator;

    [Range(0.0f, 1.0f)]
    public float bodyMass = 0.5f;

    private UMADynamicAvatar umaDynamicAvatar;
    private UMAData umaData;
    private UMADnaHumanoid umaDnaHuman;
    private UMADnaTutorial umaDnaTutor;

    private int numberOfSlots = 20;


    void GenerateUMA()
    {

        GameObject go = new GameObject("MyUMA");
        umaDynamicAvatar = go.AddComponent<UMADynamicAvatar>();

        umaDynamicAvatar.Initialize();
        umaData = umaDynamicAvatar.umaData;

        umaDynamicAvatar.umaGenerator = generator;
        umaData.umaGenerator = generator;

        umaData.umaRecipe.slotDataList = new SlotData[numberOfSlots];

        umaDnaHuman = new UMADnaHumanoid();
        umaDnaTutor = new UMADnaTutorial();
        umaData.umaRecipe.AddDna(umaDnaHuman);
        umaData.umaRecipe.AddDna(umaDnaTutor);

        CreateMale();

        umaDynamicAvatar.animationController = animator;


        umaDynamicAvatar.UpdateNewRace();

        go.transform.parent = this.gameObject.transform;

        go.transform.localPosition = Vector3.zero;
        go.transform.localRotation = Quaternion.identity;

     }

     void CreateMale()
     {
        var umaRecipe = umaDynamicAvatar.umaData.umaRecipe;
        umaRecipe.SetRace(raceLibrary.GetRace("HumanMale"));

        umaData.umaRecipe.slotDataList[0] = slotLibrary.InstantiateSlot("MaleFace");
        umaData.umaRecipe.slotDataList[0].AddOverlay(overlayLibrary.InstantiateOverlay("MaleHead02"));

    umaData.umaRecipe.slotDataList[1] = slotLibrary.InstantiateSlot("MaleEyes");
    umaData.umaRecipe.slotDataList[1].AddOverlay(overlayLibrary.InstantiateOverlay("EyeOverlay"));

    umaData.umaRecipe.slotDataList[2] = slotLibrary.InstantiateSlot("MaleInnerMouth");
    umaData.umaRecipe.slotDataList[2].AddOverlay(overlayLibrary.InstantiateOverlay("InnerMouth"));

    umaData.umaRecipe.slotDataList[3] = slotLibrary.InstantiateSlot("MaleTorso");
    umaData.umaRecipe.slotDataList[3].AddOverlay(overlayLibrary.InstantiateOverlay("MaleBody02"));

    umaData.umaRecipe.slotDataList[4] = slotLibrary.InstantiateSlot("MaleHands");
    umaData.umaRecipe.slotDataList[4].SetOverlayList(umaData.umaRecipe.slotDataList[3].GetOverlayList());

    umaData.umaRecipe.slotDataList[5] = slotLibrary.InstantiateSlot("MaleLegs");
    umaData.umaRecipe.slotDataList[5].SetOverlayList(umaData.umaRecipe.slotDataList[3].GetOverlayList());

    umaData.umaRecipe.slotDataList[6] = slotLibrary.InstantiateSlot("MaleFeet");
    umaData.umaRecipe.slotDataList[6].SetOverlayList(umaData.umaRecipe.slotDataList[3].GetOverlayList());

    umaData.umaRecipe.slotDataList[3].AddOverlay(overlayLibrary.InstantiateOverlay("MaleUnderwear01"));
    umaData.umaRecipe.slotDataList[5].AddOverlay(overlayLibrary.InstantiateOverlay("MaleUnderwear01"));

    umaData.umaRecipe.slotDataList[0].AddOverlay(overlayLibrary.InstantiateOverlay("MaleEyebrow01",Color.black));

}

// Use this for initialization
void Start () {
    GenerateUMA();
}

// Update is called once per frame
void Update () {
    if(bodyMass!=umaDnaHuman.upperMuscle)
    {
        SetBodyMass(bodyMass);
        umaData.isShapeDirty = true;
        umaData.Dirty();
    }
}

void SetBodyMass(float mass)
{
    umaDnaHuman.upperMuscle = mass;
    umaDnaHuman.upperWeight = mass;
    umaDnaHuman.lowerMuscle = mass;
    umaDnaHuman.lowerWeight = mass;
    umaDnaHuman.armWidth = mass;
    umaDnaHuman.forearmWidth = mass;
}
}

And here's the image. I want him to be as big as the chair enter image description here

\$\endgroup\$
1
\$\begingroup\$

I had my UMA as a child to a game object. I wrote a script attached to the game object that changed the transform size to a set Vector3 in the update function (I think you have to change the transform value after the UMA is generated).

 private Vector3 usualSize = new Vector3(3, 3, 3);
 private bool isFirstUpdate=true;

// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
    if(isFirstUpdate)
    {
      this.gameObject.transform.localScale = usualSize;
      isFirstUpdate=false;
    }
}
\$\endgroup\$
  • \$\begingroup\$ Scaling objects is not a good idea in terms of built-in unity physics, but scaling objects in 'Update' every frame is even worse. \$\endgroup\$ – Exerion Oct 5 '15 at 5:52
  • \$\begingroup\$ @Exerion I have fixed the every frame issue. But I don't understand your first point and how to solve it. \$\endgroup\$ – Seth Kitchen Oct 5 '15 at 13:16
  • 1
    \$\begingroup\$ Let me explain. We have a bad model of a tank that imported from 3D editor in scale of 1-to-1 and it looks tiny. You scale that model by 10 and assign mass of 3000 units. And we have normal tank. Both tanks have equal visible size, both have equal mass. But then you collide them or make any other physics-based action - the scaled tank will fly into the sky or be like monolith immovable mountain, what looks weird. It's because scaling is break unity physics. By default 1 unit of scale = 1 meter and 1 unit of mass = 1 kilogram, you need to stick with it. \$\endgroup\$ – Exerion Oct 5 '15 at 13:50
  • \$\begingroup\$ By the way, you did not fixed every frame problem, 'cause isFirstUpdate is always true. \$\endgroup\$ – Exerion Oct 5 '15 at 13:50
  • 1
    \$\begingroup\$ i had the same problem. The Update() fix it ! Thanks. \$\endgroup\$ – demosthenes Nov 19 '15 at 19:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.