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 - Laappa

Pages: [1]
1
Just to let the community know - this issue was finally solved with help of my colleague. Solution was beautifully simple, all I was missing was this:

Fsm.SaveActions();

So after creating the gameObject variable, I was saving the gameobject itself (with SetDirty), but that didn't save the GameObject owning the FSM itself thus not saving the reference.

So here's the working code if someone aims to do similar automation:

========================================

public GameObject myGameObjectReference;

public override string ErrorCheck()
{
  if (myGameObjectReference == null)
   {
      CreateNewGameObjectReference();
      return "GameObject reference missing, auto-creating it.";
    } else return null;
}

private void CreateNewGameObjectReference()
{
  myGameObjectReference = new GameObject();
  Fsm.SaveActions();
}


========================================

Cheers,
Lauri

2
Sure, here's the most simplified version of the code. So the GameObject is created, but like I wrote before, it is created every time again when I paste a new Template with this same Action. I feel like it shouldn't be a major thing to get working but I'm just stuck...

public GameObject myGameObjectReference;

public override string ErrorCheck()
{
  if (myGameObjectReference == null)
   {
      CreateNewGameObjectReference();
      return "GameObject reference missing, auto-creating it.";
    } else return null;
}

private void CreateNewGameObjectReference()
{
  myGameObjectReference = new GameObject();
  UnityEditor.EditorUtility.SetDirty(this.myGameObjectReference);
}

3
No, it's a basic Unity GameObject.

4
Yeah I think we are getting near, and the issue might be on Unity side... Initially, I actually started by using ErrorCheck to do this whole thing. I was able to create the GameObject automatically if the reference was empty. All looked good at first glance.

BUT.

The problem was that if I had already added a Template having this Action, and I added another one, the new Action called ErrorCheck on all the previous Actions as well, even though they had their GameObjects already created and assigned. So even though it _looked_ like the previous Actions HAD the GameObject (which were shown also in the Hierarchy), FSM still ran the ErrorCheck again on those States too, and created ANOTHER GameObject for them. So every time I added the template, my Hierarchy was flooded with new GameObjects, as they were created every time to each State containing the same Action. Naturally I put a check in the ErrorCheck to check if the GameObject was there already, like

if(referenceGameObject == null) InstanceNewReferenceGameObject
else don't do anything

But this still didn't catch it. The ErrorCheck still created the GameObject again. I tried SetDirty so that Unity would recognize the GameObject created in Edit mode without luck. Maybe I'm just missing the right code to check if the GameObject is there already...? But as said, checking referenceGameObject == null, or checking !referenceGameObject each return false in the Editor mode, and new GameObject was created.

Cheers,

5
Hi,

sorry I was out of office for the Easter and just saw your post. Thanks for baring with me! Unfortunately I can't use OnPreprocess, because I want to populate Action in Editor, i.e. in the phase I'm crafting my game's logic.

What I would specifically need, step by step - in the Editor mode is:

1) Paste Template that I have created (attachment 1)

2) The Template contains one State, which again contains one Action. When I paste this template as described in step #1, the Action inside the State will create the "My Game Object Reference" (attachment 2) which is a standard GameObject - in practice a copy of a Prefab - and place it in the Hierarchy as a Child of the gameobject that has the FSM. In practice I could of course do other setting here as well, but creating the gameobject is the key thing I need.

3) Then I will just fine-tune the settings of the newly created GameObject itself, if it's Prefab settings are not good off-the-shelf.

4) Then I carry on creating more States like this, independent of the previous States, NOT destroying or clearing out anything from the earlier States or their Actions.

Cheers,
Lauri

6
Hi & thanks again Alex,

I think I tried that OnPreprocess callback at some point, and tried it again: I placed that in the Action script with a Debug.Log and...unfortunately it won't call this method for some reason. I cleared all errors even, but no help, it won't call that method when pasting the Template or even when adding the action manually.

Going back to how I'm using Playmaker; I know that the "off the shelf" way is to use variables (like a GameObject variable) and attach the wanted GameObject to that Variable, even in the Inspector view. BUT that is one manual step too much in my opinion - the need to locate & drag-drop the wanted GameObjects to this Input or in the Variables tab. I'd like to spawn immediately a GameObject when adding the State. When building a "blueprint" of say a Level progression, there are dozens, hundreds of these States to be created (e.g. my enemy spawners, music starters, dialogue starters etc.), so always creating and assigning the GameObject manually to the PlayMaker State is a time-consuming activity.

Initializing things in runtime won't be a help either. When I design those Playmaker scripts, I'm doing it in Editor mode and I need to visually place those created GameObjects in the world space to their right places, before hitting play and testing it out.

If there was just a place to add code, that when pasting a Template, it would call  Reset() on its attached Action(s)...that would be essentially what I'm looking for.

Cheers
Lauri

7
Hi Alex,

thanks for you reply! Good to know all that, although I'm still wondering if I'm using Playmaker somehow wrong because I consider this missing feature so "obvious" for smooth workflow... ;D

But, to your question: I would LOVE and take all possible help you are able to give, because I'm not super comfortable with this topic, but at minimum some pointers would be needed, just to know where I need to dig & hook that additional script. I think the ideal would be to call Reset on the added Template's action(s) only, to avoid any unnecessary calls, so that it would work similarly when adding an action manually to a state. But as long as the required GameObject that I need, would be created just once (and not overrun by a new Reset-call), I'm fine with all options you can provide.

Cheers,

8
Any help with this would be highly appreciated. My system is otherwise working smoothly, but this manual addition of GameObjects is way too slow...

I've tried also to use ErrorCheck() so that when the GameObject is required, and unassigned (i.e. empty) it will go to ErrorCheck in the Action's script and create the GameObject automatically but the issue is that the same ErrorCheck() is called on EACH similar Action, which results to a situation where EACH Action will EACH time create the GameObject again when I add multiple Templates to the same FSM. For some reason I can't make Unity or Playmaker to understand that the GameObject is already created for the previous ones (even by trying setting the script Dirty), it seems to read it each time "Null". And again highlighting that all this should be able to happen in Editor, not in Playmode.

9
Hi,

I'm trying to create a smooth workflow for creating content to my game. The target is to have as automated process to add FSM 'nodes' as building blocks.

I want to:
1) Right-click on the FSM window, click "Paste Template" and paste my earlier saved template (e.g. a State, that has it's name, color and Action set ready so that the content creator doesn't need to fill those him/herself every time)

2) Then, I would want that the Action parameters would be filled automatically. And especially, auto-generating a GameObject: most of my States require an Unity GameObject reference. I want this object to be created automatically, when I "Paste Template". The script would Instantiate a copy of a Prefab that is in my Project Assets, and put it under in the Scene hierarchy

The problem is:
I have no issues, if I add my own Action - that has above functionality - manually to a State. It runs the "Reset()" code, which generates the GameObject and adds it to the Action's reference. All good. BUT then comes the tiny but annoying issue: if I "Paste Template", that has this Action, it does NOT run "OnReset". So it won't generate the GameObject. So this results with the situation that AFTER I "Paste Template", I need to manually add the Action so that it runs "Reset()". If the Action is already in the Template, it won't run "Reset()" on the Action.

My Question:
How can I automate this flow: "Paste Template", which contains my custom "Action", which calls "Reset()" method, that generates the required GameObject references, FULLY automatically?

I've been playing around this for hours now, and I'd like to seek for help...I could not find any similar posts on the Forum although I am surprised if anyone hasn't wanted to automate their workflow this far? Am I on the right track at all?

Thanks!
Lauri

Pages: [1]