playMaker

Author Topic: Problem with Get Property and Set Property [SOLVED]  (Read 4288 times)

SeriousRPG

  • Playmaker Newbie
  • *
  • Posts: 45
Problem with Get Property and Set Property [SOLVED]
« on: July 12, 2014, 04:20:28 PM »
Hi;
I am trying to use Set Property. My Target Object is a script (AutoCam) that has a variable called Target (visible in the Inspector). It is a type UnityEngine.Transform.
If I use Get Property, the Property dropdown shows "Target -> Transform" and if I select it, I can store the result in a variable of Object of type UnityEngine.Transform). This is what I expect.

If I choose Set Property, I don't get this option (I see "Target -> Euler Angles" as my first Target option). I did not expect this, I expected to see the same dropdown choices as "Get Property". Am I doing something wrong?

Thanks!
« Last Edit: July 13, 2014, 09:38:36 PM by Alex Chouls »

redikann

  • Full Member
  • ***
  • Posts: 174
Re: Problem with Get Property and Set Property
« Reply #1 on: July 13, 2014, 02:59:17 AM »
If target is exposed to the inspector as a game object it should have a nested transform. Do you have any screen shots?
Is Target a variable that gets updated in real time or always changing?
« Last Edit: July 13, 2014, 03:02:00 AM by redikann »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Problem with Get Property and Set Property
« Reply #2 on: July 13, 2014, 11:58:30 AM »
The menus for Get Property and Set Property are different because some fields/properties cannot be set, they are read only. GameObject.transform is read only, i.e., you can't do go.transform = newTransform.

You can however set the position, rotation and scale properties of the transform.

SeriousRPG

  • Playmaker Newbie
  • *
  • Posts: 45
Re: Problem with Get Property and Set Property
« Reply #3 on: July 13, 2014, 05:34:30 PM »
Script is Auto Cam (see attached inspector) and attribute in question is Target. It is a transform type but in the inspector you can pick a different target and it works - just not able to get it to change values at runtime with playmaker.  In script it is declared as:
   [SerializeField] protected Transform target;       

and this relevant functions:
public virtual void SetTarget (Transform newTransform) {
      target = newTransform;
   }
   
public Transform Target { get { return this.target; } }
   
   

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: Problem with Get Property and Set Property
« Reply #4 on: July 13, 2014, 05:58:37 PM »
Are you using Set Property on the target property of the Auto Cam component? E.g., drag the Auto Cam component into the State panel, select Set Property then select target.

You might need to make target public instead of protected (not at my computer to test if Set Property sees protected fields).


« Last Edit: July 13, 2014, 06:00:57 PM by Alex Chouls »

SeriousRPG

  • Playmaker Newbie
  • *
  • Posts: 45
Re: Problem with Get Property and Set Property
« Reply #5 on: July 13, 2014, 06:59:03 PM »
I was using Set Property correctly but once I changed target from Protected to Public I was able to see it in the dropdowns (whereas previously it was not there).  I guess Set Property doesn't work on Protected variables.

Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Problem with Get Property and Set Property [SOLVED]
« Reply #6 on: July 16, 2014, 09:22:17 AM »
Hi,

 exactly, no public property are accessible.

 Bye,

 Jean

VivaLaBaz

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Problem with Get Property and Set Property
« Reply #7 on: October 22, 2015, 03:34:00 AM »
Script is Auto Cam (see attached inspector) and attribute in question is Target. It is a transform type but in the inspector you can pick a different target and it works - just not able to get it to change values at runtime with playmaker.  In script it is declared as:
   [SerializeField] protected Transform target;       

and this relevant functions:
public virtual void SetTarget (Transform newTransform) {
      target = newTransform;
   }
   
public Transform Target { get { return this.target; } }

Which Auto Cam script is that? The one which comes with unitys camera doesn't have that section of code so its physically impossible for me to make it public,

Code: [Select]
using System;
using UnityEngine;
#if UNITY_EDITOR

#endif

namespace UnityStandardAssets.Cameras
{
    [ExecuteInEditMode]
    public class AutoCam : PivotBasedCameraRig
    {
        [SerializeField] public float m_MoveSpeed = 3; // How fast the rig will move to keep up with target's position
        [SerializeField] private float m_TurnSpeed = 1; // How fast the rig will turn to keep up with target's rotation
        [SerializeField] private float m_RollSpeed = 0.2f;// How fast the rig will roll (around Z axis) to match target's roll.
        [SerializeField] private bool m_FollowVelocity = false;// Whether the rig will rotate in the direction of the target's velocity.
        [SerializeField] private bool m_FollowTilt = true; // Whether the rig will tilt (around X axis) with the target.
        [SerializeField] private float m_SpinTurnLimit = 90;// The threshold beyond which the camera stops following the target's rotation. (used in situations where a car spins out, for example)
        [SerializeField] private float m_TargetVelocityLowerLimit = 4f;// the minimum velocity above which the camera turns towards the object's velocity. Below this we use the object's forward direction.
        [SerializeField] private float m_SmoothTurnTime = 0.2f; // the smoothing for the camera's rotation
       
        private float m_LastFlatAngle; // The relative angle of the target and the rig from the previous frame.
        private float m_CurrentTurnAmount; // How much to turn the camera
        private float m_TurnSpeedVelocityChange; // The change in the turn speed velocity
        private Vector3 m_RollUp = Vector3.up;// The roll of the camera around the z axis ( generally this will always just be up )


        protected override void FollowTarget(float deltaTime)
        {
            // if no target, or no time passed then we quit early, as there is nothing to do
            if (!(deltaTime > 0) || m_Target == null)
            {
                return;
            }

            // initialise some vars, we'll be modifying these in a moment
            var targetForward = m_Target.forward;
            var targetUp = m_Target.up;

            if (m_FollowVelocity && Application.isPlaying)
            {
                // in follow velocity mode, the camera's rotation is aligned towards the object's velocity direction
                // but only if the object is traveling faster than a given threshold.

                if (targetRigidbody.velocity.magnitude > m_TargetVelocityLowerLimit)
                {
                    // velocity is high enough, so we'll use the target's velocty
                    targetForward = targetRigidbody.velocity.normalized;
                    targetUp = Vector3.up;
                }
                else
                {
                    targetUp = Vector3.up;
                }
                m_CurrentTurnAmount = Mathf.SmoothDamp(m_CurrentTurnAmount, 1, ref m_TurnSpeedVelocityChange, m_SmoothTurnTime);
            }
            else
            {
                // we're in 'follow rotation' mode, where the camera rig's rotation follows the object's rotation.

                // This section allows the camera to stop following the target's rotation when the target is spinning too fast.
                // eg when a car has been knocked into a spin. The camera will resume following the rotation
                // of the target when the target's angular velocity slows below the threshold.
                var currentFlatAngle = Mathf.Atan2(targetForward.x, targetForward.z)*Mathf.Rad2Deg;
                if (m_SpinTurnLimit > 0)
                {
                    var targetSpinSpeed = Mathf.Abs(Mathf.DeltaAngle(m_LastFlatAngle, currentFlatAngle))/deltaTime;
                    var desiredTurnAmount = Mathf.InverseLerp(m_SpinTurnLimit, m_SpinTurnLimit*0.75f, targetSpinSpeed);
                    var turnReactSpeed = (m_CurrentTurnAmount > desiredTurnAmount ? .1f : 1f);
                    if (Application.isPlaying)
                    {
                        m_CurrentTurnAmount = Mathf.SmoothDamp(m_CurrentTurnAmount, desiredTurnAmount,
                                                             ref m_TurnSpeedVelocityChange, turnReactSpeed);
                    }
                    else
                    {
                        // for editor mode, smoothdamp won't work because it uses deltaTime internally
                        m_CurrentTurnAmount = desiredTurnAmount;
                    }
                }
                else
                {
                    m_CurrentTurnAmount = 1;
                }
                m_LastFlatAngle = currentFlatAngle;
            }

            // camera position moves towards target position:
            transform.position = Vector3.Lerp(transform.position, m_Target.position, deltaTime*m_MoveSpeed);

            // camera's rotation is split into two parts, which can have independend speed settings:
            // rotating towards the target's forward direction (which encompasses its 'yaw' and 'pitch')
            if (!m_FollowTilt)
            {
                targetForward.y = 0;
                if (targetForward.sqrMagnitude < float.Epsilon)
                {
                    targetForward = transform.forward;
                }
            }
            var rollRotation = Quaternion.LookRotation(targetForward, m_RollUp);

            // and aligning with the target object's up direction (i.e. its 'roll')
            m_RollUp = m_RollSpeed > 0 ? Vector3.Slerp(m_RollUp, targetUp, m_RollSpeed*deltaTime) : Vector3.up;
            transform.rotation = Quaternion.Lerp(transform.rotation, rollRotation, m_TurnSpeed*m_CurrentTurnAmount*deltaTime);
        }
    }
}