playMaker

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - paradoxjester

Pages: [1]
1
Playmaker Help / [SOLVED] FSM Template Creation via Code
« on: September 25, 2018, 08:52:38 AM »
Hello!

I have been trying for awhile now to create an FSM Template Via code, and i have been failing miserably. I have been using this method:

Code: [Select]
public static void GenerateTemplate(Effect effect) {
var fsmTemplate = (FsmTemplate)CreateInstance(typeof(FsmTemplate));
fsmTemplate.Category = "HotspotEffect";

fsmTemplate.fsm = new Fsm {
DataVersion = Convert.ToInt32(DateTime.Today.ToString("ddMM")),
UsedInTemplate = fsmTemplate,
Name = effect.name.SnakeCaseToCapitalizedCase()
};

var startEvent = new FsmEvent("START " + effect.name.SnakeCaseToUpperCase());
var startTransition = new FsmTransition
{
FsmEvent = startEvent,
ToState = effect.name.SnakeCaseToCapitalizedCase()
};
var applyState = new FsmState(fsmTemplate.fsm)
{
Name = effect.name.SnakeCaseToCapitalizedCase(),
Position = new Rect(130, 60, 128, 30),
Transitions = new[]
{
new FsmTransition {
                    FsmEvent = FsmEvent.Finished,
                    ToState = "After " + effect.name.SnakeCaseToCapitalizedCase()
                }
}
};
var finishState = new FsmState(fsmTemplate.fsm)
{
Name = "After " + effect.name.SnakeCaseToCapitalizedCase(),
Position = new Rect(130, 120, 128, 15)
};
var finishAction = new FinishHotspotAction();
// Documentation says: "Called in the editor when an action is added to a state or reset". Not clear if via code is needed, apparently it does not generate errors.
//finishAction.Reset();
finishState.Actions = new FsmStateAction[] { finishAction };
finishState.SaveActions();

fsmTemplate.fsm.States = new[] { applyState, finishState };
fsmTemplate.fsm.Events = new[] { startEvent };
fsmTemplate.fsm.GlobalTransitions = new[] { startTransition };

AssetDatabase.CreateAsset(fsmTemplate, @"Assets\PlaymakerCustomTemplates\" + effect.name + ".asset");
AssetDatabase.SaveAssets();

effect.templateFSM = fsmTemplate;
}

The template is generated correctly, in the folder specified. Everything is working fine, however, when i try to move or add any state to the template, this happens:

Quote
NullReferenceException: Object reference not set to an instance of an object
HutongGames.PlayMakerEditor.FsmGraphView.UpdateGraphBounds (Vector2 viewPos, Single padding) (at .../PlayMaker/Editor/Classes/FsmGraphView.cs:337)

I believe this issue is here because i'm not creating templates the way Hutong Games intended (whichever way it is), so i come here to ask:
What is the right way to create and istantiate an FSM Template?

I do believe that i'm supposed to use the FSMBuilder class, however even when using that, i can't seem to get anywhere, as i don't know how to load an Fsm, or export one to a template. I've been fighting with this system for days, can anyone help?

2
Playmaker Help / Copying actions between states [SOLVED]
« on: August 17, 2018, 07:12:14 AM »
Hello!

I have set out to create an editor script that replicates what is contained within an FSM template into what is contained within a PlayMaker FSM component. The end result should be an FSM inside my PlayMaker FSM component that contains all of the states, all of the events, all of the transitions and the variables contained within the Template, but with no actual reference to the Template itself!
I'm having a slight issue. When it comes to copying over States' actions, i'm copying over the whole 'Actions' array, contained within each of my Template's states into each of the corresponding PlayMaker FSM states, which i am copying over. The problem is, because each member of that array is of Class FsmStateAction and not of the more specific inherited subclass, then i cannot specify each action's parameters, or copy it over correctly. If i were to do a shallow copy (just assigning it, or using the array Copy function), then the reference to the template would remain, and any operation made on the action in the template would also affect the action in the PlayMaker FSM component, and viceversa. Is there any way i can copy over the actions contained a state over to the ones contained in another, cutting away any ties that the actions have to their previous state? This is all done via editor script, not at runtime! If anyone has a clue, it would be greatly appreciated! If you need any code examples of the work done up to now i can provide it.

Kind Regards,
Lorenzo

3
Hey everyone,

I'm creating some editor scripts in unity, and i was asked to set a PlayMakerFSM component's inner FSM value to be the instance of a FSM Template. This FSM Template is stored in a Scriptable Object, and when the Scriptable Object is assigned to the GameObject, then the FSM value of the PlayMakerFSM component should change. I don't want to set the PlayMakerFSM's template to be the FSM Template, i want the inner FSM to be a copy of the FSM Template. I can extract an instance from the template using the FsmTemplateControl class, but i don't know how to insert it in the component.
Can anyone help? I'd be very grateful ,:D

Pages: [1]