playMaker

Author Topic: How to convert any object to FsmObject  (Read 135 times)

blackant

  • Sr. Member
  • ****
  • Posts: 413
  • http://blackantmaster.com
    • View Profile
    • blackantmaster.com
How to convert any object to FsmObject
« on: April 02, 2019, 04:33:40 AM »
Hi,

i'm writing actions for AI.NavMesh,
but there is a lot of custom type in there, and i would like to store them in fsm variable

for some i can do it easily,
but not always....

the problem for now is this one:

[ObjectType(typeof(NavMeshPath))]
public FsmObject PathObject;

it can be stored there without problem, but i cannot call it  with PathObject.Value

i tested many variants without succes.

so i missed something but what ?

thanks

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4116
    • View Profile
    • jinxtergames
Re: How to convert any object to FsmObject
« Reply #1 on: April 02, 2019, 05:24:40 AM »
Hi.

have you tried :

Code: [Select]
PathObject.Value as NavMeshPath;

blackant

  • Sr. Member
  • ****
  • Posts: 413
  • http://blackantmaster.com
    • View Profile
    • blackantmaster.com
Re: How to convert any object to FsmObject
« Reply #2 on: April 03, 2019, 02:29:36 AM »
yes, just tested but doesn't work

have also tested:
(NavMeshPath)PathObject.Value;
« Last Edit: April 03, 2019, 03:18:04 AM by blackant »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4116
    • View Profile
    • jinxtergames
Re: How to convert any object to FsmObject
« Reply #3 on: April 03, 2019, 02:10:37 PM »
Hi.
There is also a .RawValue.

it is also possible that you need to place the fsm var in a var first and then do what you are trying to do.

Can you share the script. you can use paste bin or paste here as code.

blackant

  • Sr. Member
  • ****
  • Posts: 413
  • http://blackantmaster.com
    • View Profile
    • blackantmaster.com
Re: How to convert any object to FsmObject
« Reply #4 on: April 03, 2019, 10:14:47 PM »
also tested Var but got same result, no implicit conversion possible between them
and .RawValue neither

here is the code:
Code: [Select]
[RequiredField]
[CheckForComponent(typeof(NavMeshAgent))]
[UIHint(UIHint.Variable)]
[Tooltip("The NavMesh Agent.")]
public FsmOwnerDefault Agent;

[ObjectType(typeof(NavMeshPath))]
public FsmObject PathObject;

NavMeshPath Path;

public FsmBool Success;

public FsmBool everyFrame;
// Code that runs on entering the state.
public override void OnEnter()
{
DoSetPath();
if (!everyFrame.Value)
{
Finish();
}
}

// Code that runs every frame.
public override void OnUpdate()
{
DoSetPath();
}

void DoSetPath()
{
Path = PathObject.Value;
Success.Value = Fsm.GetOwnerDefaultTarget(Agent).GetComponent<NavMeshAgent>().SetPath(Path);
}

what really bother me is that if i declare PathObject to be [ObjectType(typeof(NavMeshPath))]

why do i have to convert it's value again into NavMeshPath ??

byte are strange...
« Last Edit: April 03, 2019, 10:22:52 PM by blackant »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4116
    • View Profile
    • jinxtergames
Re: How to convert any object to FsmObject
« Reply #5 on: April 05, 2019, 05:28:20 AM »
hi.

if i set :

Code: [Select]
Path = PathObject.RawValue as NavMeshPath;
i don't get errors

but i did not have time to test the script

you can also set it this way :

Code: [Select]
Success.Value = Fsm.GetOwnerDefaultTarget(Agent).GetComponent<NavMeshAgent>().SetPath(PathObject.RawValue as NavMeshPath);
then you dont need the path variable