playMaker

Author Topic: getting null result when assigning a variable  (Read 620 times)

cel

  • Full Member
  • ***
  • Posts: 132
getting null result when assigning a variable
« on: July 16, 2021, 10:04:59 AM »
Hi,

trying to make a playmaker action for Gamecreator.
I'm having problems accessing the Gamecreator CharacterAttachments method, when trying to assign it i always get a null result. Can anyone with knowledge of Playmaker and Gamecreator have a look and point me in the right direction?

Thanks in advance,

Here's the code:

using UnityEngine;
using GameCreator.Characters;
using GameCreator.Core;
using UnityEngine.Events;


namespace HutongGames.PlayMaker.Actions
{

    [ActionCategory("GameCreator")]
    public class test1 : FsmStateAction
    {
        [RequiredField]
        [ObjectType(typeof(Character))]
        [Tooltip("Character to attach to")]
        public FsmOwnerDefault character;

        [ObjectType(typeof(HumanBodyBones))]
        [Tooltip("Bone where gameobject will be attached")]
        public FsmEnum Bone;

        [RequiredField]
        [Tooltip("Gameobject to attach")]
        public FsmGameObject objectToAttach;

        [ObjectType(typeof(Space))]
        [Tooltip("Space")]
        public FsmEnum space;

        [Tooltip("Position")]
        public FsmVector3 position;

        [Tooltip("Rotation")]
        public FsmQuaternion rotation;

        private Character _character1;
        private CharacterAnimator _animator;
        private CharacterAttachments _attachments;
        private GameObject _object;

        // Code that runs on entering the state.
        public override void OnEnter()
        {
            var go = Fsm.GetOwnerDefaultTarget(character);
            if (go == null) return;

            _character1 = go.GetComponent<Character>();
            _animator = _character1.GetCharacterAnimator();
            _attachments = _animator.GetComponent<CharacterAttachments>();
            _object = objectToAttach.Value;


            if (_character1 == null) Debug.LogError("no character");
            if (_animator == null) Debug.LogError("no animator");
            if (_attachments == null) Debug.LogError("no attachments");
            if (_object == null) Debug.LogError("no object");
           
            Finish();
        }
    }

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: getting null result when assigning a variable
« Reply #1 on: July 21, 2021, 12:01:08 PM »
Hi.
Code: [Select]
    [ObjectType(typeof(Character))]
        [Tooltip("Character to attach to")]
        public FsmOwnerDefault character;

this might not work as FsmOwnerDefault hold a game object and you are loking for the type of Character

you can try to use fsmobject instead of FsmOwnerDefault
or remove [ObjectType(typeof(Character))]
and if it needs "Character Component" you can use 'Check For component'