edited November 2017 in ORK Scripting
Hey folks, I bought Ork a few years back, can't remember. Had to recreate my account as I couldn't remember my old one.

I wasn't sure what forum to make this thread in so, sorry to the mods.

I have sucessfully completed the tutorials up this one here: unity3d-dk-tools.boards.net/thread/43/prepare-ork-framework-uma-equipment

I have been lurking on these forums for awhile so I know @Keldryn has integrated uma with ork, so his input would be great, thanks.

Anyway here is the trouble I have been having so far.

I don't know whether it is my lack of understanding, however when i click the "Add all Equipment Parts" Button I get this null ref: NullReferenceException: Object reference not set to an instance of an object
Prepare4ORK.AddAllEquipmentPlaces () (at Assets/DK Editors/DK_UMA_Editor/PlugIns/Integrations/ORK Framework/Scripts/PrepareORK.cs:176)
DK_UMA_ORK_Win.OnGUI () (at Assets/DK Editors/DK_UMA_Editor/PlugIns/Integrations/ORK

I can't legally post the entire script but here is the offending block of code.

I didn't write the code messy like that, it came like this.

public static void AddAllEquipmentPlaces ()
{
GameObject GeneratorPresets = GameObject.Find ("Generator Presets");
DK_GeneratorPresetLibrary PresetLibrary = GeneratorPresets.transform.GetComponentInChildren<DK_GeneratorPresetLibrary>();

foreach ( DK_SlotsAnatomyElement place in PresetLibrary.dk_SlotsAnatomyElementList.ToList() ){
if ( place.IsEquipment
&& ORKFramework.ORK.EquipmentParts.GetNames(false).ToList().Contains(place.dk_SlotsAnatomyElement.dk_SlotsAnatomyName.Replace("Wear", "") ) == false ) {
ORKFramework.EquipmentPart part = new ORKFramework.EquipmentPart(place.dk_SlotsAnatomyElement.dk_SlotsAnatomyName.Replace("Wear", ""));

int index = ORKFramework.ORK.EquipmentParts.Add ();
ORKFramework.ORK.EquipmentParts.data[index] = part;
}


I don't understand I have the ork editor open as the guide suggests. What do you think is wrong?

Thank you in advance. :)
Post edited by DanielKW on
  • Well, my first suggestion would be to ditch DK UMA and just go with the Dynamic Character System that was added in UMA 2.5.

    DK adds another massive layer of complexity and in my experience has been a frequent source of bugs and build errors. It's another one of those dependencies that I would avoid taking on.

    You won't get the same full featured in-game character editor/creator that you do with DK; you'll have to adapt one of the DCS demos on your own.

    But it's super easy to get DCS working with ORK. It's basically just a component on an empty GameObject prefab (which is used as the Viewer prefab). I'll share my code for it later today, when I'm on my computer.
  • Thank you @Keldryn. I will remove DK as I never wanted to use it anyway, I saw that it had an "integration" with Ork. UMA by itself was lacking in the manual department in relation to Ork so that's how i ended up here.

    Anyway I like this community, It's one of the most responsive and respectful forums I've been on. :)
  • You're welcome, @DanielKW.

    DK UMA was a cool extension on top of UMA 2.0 -- I don't want to come off as entirely dismissive of it. At the time, your only alternative was to code your own framework for a system of interchangeable clothing, armor pieces, etc.

    UMA is a very complex system, and layering another complex system on top of it produced a lot of headaches (in my experience). When DCS was included as a native part of UMA 2.5, it was clearly the better option, as it was simpler and fully integrated with the core UMA package. There are things that DK does out of the box that DCS doesn't, but I'd rather go with what is likely the more stable solution and extend it.

    I think that DK could be re-worked as an extension of DCS (i.e. building off WardrobeRecipes instead of using its own separate slots & overlays), and I'd be quite interested in checking that out. But that's a pretty major rewrite of much of the system.

    Anyway, here's the component I mentioned:

    using UnityEngine;
    using UMA.CharacterSystem;


    namespace ORKIntegrationLibrary.UMA_DCS
    {
    public class DynamicEquipmentItem : MonoBehaviour
    {
    [SerializeField]
    private string wardrobeSlot;

    [SerializeField]
    private UMAWardrobeRecipe _maleItemRecipe;

    [SerializeField]
    private UMAWardrobeRecipe _femaleItemRecipe;

    private bool _isAdded = false;
    private bool _isRemoved = false;

    private DynamicCharacterAvatar _avatar;
    private bool _useFemaleRecipe;

    void Start()
    {
    _avatar = GetComponentInParent<DynamicCharacterAvatar>();

    if (_avatar == null)
    {
    Debug.Log("DynamicEquipmentItem: Could not get DynamicCharacterAvatar component!");
    return;
    }

    _useFemaleRecipe = _avatar.activeRace.name.ToUpper().Contains("FEMALE");
    EquipItem();
    }

    private void EquipItem()
    {
    if (_useFemaleRecipe)
    {
    if (_femaleItemRecipe == null) { return; }
    _avatar.SetSlot(_femaleItemRecipe);
    }
    else
    {
    if (_maleItemRecipe == null) { return; }
    //Debug.Log("DynamicEquipmentItem: Equipping " + _maleItemRecipe.DisplayValue);
    _avatar.SetSlot(_maleItemRecipe);
    }

    _isAdded = true;
    _avatar.BuildCharacter(true);

    }

    private void OnDisable()
    {
    if (_avatar != null)
    {
    _avatar.ClearSlot(wardrobeSlot);
    _avatar.BuildCharacter(true);

    }

    _isRemoved = true;
    }
    }
    }


    For clothing/armor items that are handled using UMA, I simply create an empty GameObject and add this component to it, then use that to create the Viewer Prefab. Just specify the name of the wardrobe slot, and then names of the male and female wardrobe recipes, and that's it.

    I also create an empty GameObject as a child of the UMA character prefab (called "Equipment Setup" or something like that), and I place all of the Equipment Viewers for such items on that. No sense in fiddling around placing them on the corresponding bones of the skeleton when the items won't actually be mounted to the bones anyway.

    The Start() method is called as soon as the prefab is instantiated, and that adds the item to the Avatar and rebuilds it.

    If you're using ORK Equipment Viewers for weapons (say if you're not using an advanced character controller and its weapon placement system), then you can either add them via a script or you can get the UMA 2.7 Beta from Github and use the new Bone Builder feature to create the skeleton at design-time and set up the viewers as you normally would.

    If you want to do it via script, you can adapt mine if you like:

    using UnityEngine;
    using System.Collections;
    using UMA;
    using ORKFramework.Behaviours;

    namespace ORKIntegrationLibrary.UMA_DCS
    {
    public class ORKDynamicAvatarSetup : MonoBehaviour
    {
    [System.Serializable]
    public class EquipmentViewerPrefabItem
    {
    public GameObject viewerPrefab;
    public Vector3 positionOffset;
    public Vector3 rotationOffset;
    }

    public bool createSheathedViewers = false;

    static int headHash;
    static int rightHandHash;
    static int hipsHash;
    static bool hashesFound = false;

    [Header("Weapon Viewer Prefab")]
    [SerializeField]
    private EquipmentViewerPrefabItem _rightHandSlot;

    [Header("Sheath Viewer Prefab")]
    [SerializeField]
    private EquipmentViewerPrefabItem _rightHandSheath;


    public void SetupAvatar(UMAData umaData)
    {
    SetupEquipmentViewers(umaData);
    }

    private void SetupEquipmentViewers(UMAData umaData)
    {
    if (!hashesFound)
    {
    rightHandHash = UMAUtils.StringToHash("RightHand");

    hipsHash = UMAUtils.StringToHash("Hips");
    headHash = UMAUtils.StringToHash("Head");
    hashesFound = true;
    }

    GameObject head = umaData.GetBoneGameObject(headHash);
    GameObject rightHand = umaData.GetBoneGameObject(rightHandHash);
    GameObject hips = umaData.GetBoneGameObject(hipsHash);

    //if (head.GetComponent<EquipmentViewer>() == null)
    //{
    // var viewer = head.AddComponent<EquipmentViewer>();
    // viewer.partID = ORKEquipmentPart.HELMET;
    //}

    //var torsoViewer = hips.AddComponent<EquipmentViewer>();
    //torsoViewer.partID = ORKEquipmentPart.TORSO;

    //var legsViewer = hips.AddComponent<EquipmentViewer>();
    //legsViewer.partID = ORKEquipmentPart.LEGS;

    //var feetViewer = hips.AddComponent<EquipmentViewer>();
    //feetViewer.partID = ORKEquipmentPart.FEET;


    if (_rightHandSlot != null)
    {
    Debug.Log("adding Right Hand slot");
    var rightHandItems = Instantiate(_rightHandSlot.viewerPrefab, rightHand.transform.position, Quaternion.identity) as GameObject;
    if (rightHandItems != null)
    {
    rightHandItems.transform.parent = rightHand.transform;
    rightHandItems.transform.localPosition = _rightHandSlot.positionOffset;
    rightHandItems.transform.localRotation = Quaternion.Euler(_rightHandSlot.rotationOffset);
    rightHandItems.transform.localScale = Vector3.one;
    }
    }
    else
    {
    Debug.Log("EquipmentViewersSlotScript: no prefab set for Right Hand Slot");
    }

    if (_rightHandSheath != null && createSheathedViewers)
    {
    var rightHandItems = Instantiate(_rightHandSheath.viewerPrefab, hips.transform.position, Quaternion.identity) as GameObject;
    if (rightHandItems != null)
    {
    rightHandItems.transform.parent = hips.transform;
    rightHandItems.transform.localPosition = _rightHandSheath.positionOffset;
    rightHandItems.transform.localRotation = Quaternion.Euler(_rightHandSheath.rotationOffset);
    rightHandItems.transform.localScale = Vector3.one;
    }
    }
    }
    }
    }


    The nested EquipmentViewerPrefabItem serializable class lets you specify the local position and rotation offset values for that particular viewer; the viewerPrefab here is just an empty GameObject with an ORK EquipmentViewer component on it, with the EquipPartID and visibility settings configured as appropriate.

    The commented out part shows how you could add the EquipmentViewers for UMA slot items. The EquipPartIDs there use generated constants; if you look in the Tutorials section here, there's a post of mine with a script to generate these values from your ORK project file. Or you could just use integer ids.

    You call this script (SetupAvatar method) from the CharacterCreated event on the Dynamic Character Avatar.
  • Thanks @Keldryn I'll try this tomorrow and then update you on how I go. :)
  • edited November 2017
    Just to be clear @Keldryn when you say "Dynamic Character Avatar" are you refering to the script Dynamic Character Avatar or UMA Dynamic Avatar, Because for me the Uma Dynamic Avatar has the 'characterCreated' fields and the Dynamic Character Avatar had no options for me apart from the help boolean.

    Scratch that, there was something weired going on with my project. I fixed the problem and now see the character created field under events.
    Post edited by DanielKW on
  • I have a question @Keldryn.

    So for armor/clothing/wearables, do I simply leave the "Viewer" prefab on the "Equipment Setup" to disabled and then reenable it when I equip a inventory item, is that how you meant, because I'm finding it hard to follow. Thanks.
  • Thank you @Keldryn, it nearly took me a whole week, I managed to get everything working as intended. Free Cookies for everyone! :)
  • edited December 2017
    You're welcome @DanielKW! Glad it all worked out.

    Sorry I missed your question on the 25th... Wasn't ignoring you intentionally.

    Can those be (Gluten) Free Cookies? I have a fairly strong wheat allergy. ;-)
    Post edited by Keldryn on
  • No problem @Keldryn. Here (Throws Keldryn a gluten free cookie) :)
  • edited December 2017
    Sorry to bother you again @Keldryn, however I have run into another problem. The armor I have equipped on the player; via start equipment, (havn't got an inventory UI yet) is equipping fine, however I can't seem to get the boots to appear, they stay invisible, but I know they are equipped via the inspector.

    A clearer run down or check list might help for people googling as well. Thanks.

    Also I noticed, In your fantasy rpg, are your UMAs using multi-table armors or is it all packaged into one recipe?
    Post edited by DanielKW on
  • I'm using one recipe per ORK item for the boots and helmets, and then I have a single "armor" item that contains both chest and legs wardrobe recipes. I need to open up that project and refresh my memory as to exactly how I set them up.

    Not sure why your boots aren't showing up. When I get a chance I'll try and get screenshots of how mine are set up.
  • Okay, here are a few of my Equipment Viewer Prefabs:

    image

    image

    image

    And the Equipment Viewer component for the Armor equipment part:

    image

    Nothing else to it, really. Just the component on the viewer prefab, and an Equipment Viewer (which doesn't need to be on a specific bone).

  • Thanks @Keldryn I have tried what you posted, it helped and give me an idea on what to do, however It hasn't worked for me.

    I think it maybe the UMA mesh I made, I'll try remaking it and importing into unity. See if that helps.
  • edited December 2017
    Hey @Keldryn Would it be alright if I zipped up my project and sent it to you to look at? I've been having real trouble with it. I'd really appreciate it.

    I can share my google drive link to it.
    Post edited by DanielKW on
  • Sure, just send me a PM.

    (Sorry, this never got posted... sat here as a draft for several days. I responded right after posting a comment on another thread and I got locked from posting for 120 seconds. And promptly forgot to come back to post when the time was up)
Sign In or Register to comment.