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.


Messages - paradoxjester

Pages: [1]
1
Playmaker Help / Re: FSM Template Creation via Code
« on: October 11, 2018, 12:56:15 AM »
Hello!

Thank you so much for the wonderful help! We've worked around the start state issue, and now everything works with the rest of the project.

Thank you so much!

2
Playmaker Help / Re: FSM Template Creation via Code
« on: October 09, 2018, 01:29:34 AM »
Hello!

Thank you, if i add a start state then everything works fine!
Unfortunately, our generated templates would be cleaner without a start state...
I thought it was possible to copy states and save them into a template without a start state! Is it not?
Let me know if this is a possibility!

3
Playmaker Help / Re: FSM Template Creation via Code
« on: October 08, 2018, 01:23:47 AM »
Hello!

Sure, here it is:

Code: [Select]
public static void GenerateTemplate(string effectName) {
var fsmTemplate = (FsmTemplate)CreateInstance(typeof(FsmTemplate));

fsmTemplate.Category = "HotspotEffect";

fsmTemplate.fsm = new Fsm();
fsmTemplate.fsm.Reset(null);

var startEvent = new FsmEvent("START " + effectName);
var startTransition = new FsmTransition
{
FsmEvent = startEvent,
ToState = effectName
};
var applyState = new FsmState(fsmTemplate.fsm)
{
Name = effectName,
Position = new Rect(130, 60, 128, 30),
Transitions = new[]
{
new FsmTransition {
FsmEvent = FsmEvent.Finished,
ToState = "After " + effectName
}
}
};
var finishState = new FsmState(fsmTemplate.fsm)
{
Name = "After " + effectName,
Position = new Rect(130, 120, 128, 15)
};
var finishAction = new DebugLog();
finishState.Actions = new FsmStateAction[] { finishAction };
finishState.SaveActions();
fsmTemplate.fsm.States = new[] { applyState, finishState };
fsmTemplate.fsm.Events = new[] { startEvent };
fsmTemplate.fsm.GlobalTransitions = new[] { startTransition };
fsmTemplate.fsm.Name = effectName;
fsmTemplate.fsm.UsedInTemplate = fsmTemplate;

AssetDatabase.CreateAsset(fsmTemplate, @"Assets\Data\PlaymakerCustomTemplates\" + effectName + ".asset");
AssetDatabase.SaveAssets();
}

I used a string instead of my class, and switched out my custom action for the DebugLog() action, included in Playmaker. The issue still appears. The function is static because i run it via a button in the editor, using my custom editor script, but it should also work if you call it non-statically, so feel free to remove that. Also feel free to change the path at which i save the created Template.

Thank you very much!

4
Playmaker Help / Re: FSM Template Creation via Code
« on: October 05, 2018, 01:01:18 AM »
Hello!

Unfortunately that didn't do it for us :(
I'm gonna paste what my generation code looks like:

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

fsmTemplate.Category = "HotspotEffect";

fsmTemplate.fsm = new Fsm();
fsmTemplate.fsm.Reset(null);

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 };
fsmTemplate.fsm.Name = effect.name.SnakeCaseToCapitalizedCase();
fsmTemplate.fsm.UsedInTemplate = fsmTemplate;

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

effect.templateFSM = fsmTemplate;
}

Again, the issue isn't on the generation, it's on manipulating the generated template afterwards. When i try to move any state around, the pointer gets stuck on that state, and i start getting alot of errors in the console  :(

5
Playmaker Help / Re: FSM Template Creation via Code
« on: October 04, 2018, 03:56:41 AM »
Thanks alot!
I'll be waiting for your tests, and check out some more things on my own :)

6
Playmaker Help / Re: FSM Template Creation via Code
« on: October 03, 2018, 12:54:50 AM »
Hello,

I've tried using the provided code, however the same error seems to happen. As soon as i click on a state or try to move anything in the template, that error appears in the console, and the state i'm trying to move sticks to my cursor, and i can't remove it.  :'(

7
Playmaker Help / Re: FSM Template Creation via Code
« on: October 02, 2018, 12:25:56 AM »
Bump!

8
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?

9
Playmaker Help / Re: Copying actions between states
« on: August 24, 2018, 06:57:21 AM »
Hello!

Unfortunately, i was not very thorough in searching for methods, and i realized that simply using
Code: [Select]
FsmState.CopyActionData(FsmState state) will copy the actions with parameters from one state to another, removing the connection between the two ;D. I should have looked better!

Thanks anyways!

10
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

11
Playmaker Help / Re: Setting a PlayMakerFSM Component's FSM via script
« on: August 17, 2018, 04:21:38 AM »
Hi,

Thank you for answering. This is not something i planned on doing at runtime, instead i'm doing this via editor. I want to copy the contents of a template (its states, transitions and events) into the FSM of a PlayMakerFSM component, but breaking off the reference to the original template, this way if the component's FSM is modified, it will not modify the original template's FSM. I have achieved this by copying all of the Template's states, events and transitions individually into the component's FSM. Everything seems to be working correctly!
Thank you again!

12
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]