playMaker

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

blackant

  • Hero Member
  • *****
  • Posts: 521
  • http://blackantmaster.com
    • blackantmaster.com
How to convert any object to FsmObject
« on: April 02, 2019, 07: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: 7615
    • jinxtergames
Re: How to convert any object to FsmObject
« Reply #1 on: April 02, 2019, 08:24:40 AM »
Hi.

have you tried :

Code: [Select]
PathObject.Value as NavMeshPath;

blackant

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

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

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: How to convert any object to FsmObject
« Reply #3 on: April 03, 2019, 05: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

  • Hero Member
  • *****
  • Posts: 521
  • http://blackantmaster.com
    • blackantmaster.com
Re: How to convert any object to FsmObject
« Reply #4 on: April 04, 2019, 01:14:47 AM »
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 04, 2019, 01:22:52 AM by blackant »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7615
    • jinxtergames
Re: How to convert any object to FsmObject
« Reply #5 on: April 05, 2019, 08: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
« Last Edit: April 05, 2019, 08:30:22 AM by djaydino »