playMaker

Author Topic: How to prepare things to be 'replaceable' and 'scalable'?  (Read 1258 times)

rechronicle

  • Full Member
  • ***
  • Posts: 119
  • Mystvaldia
    • Indie RPG Creator
How to prepare things to be 'replaceable' and 'scalable'?
« on: May 19, 2019, 10:55:44 AM »
Hello,
I have tried to make some games using Playmaker.
Then I found this obstacle:


---
I always keep in my mind that I need to make everything working first and worry about graphic/variant later. (This variant can be more enemies, more weapons, levels, etc.)

And then... it's time to put the variant.

The problem is, replacing one thing will break the connection of everything.
For examples, the game system only knows the current enemies object and replacing it with a new one will make it disconnect/broken. Or the skill can only be used to that one enemy and no other enemy. And so on...

As a result, the project becomes stuck. It's like impossible to add new things without breaking everything else.
---


Because this 'problem' keeps recurring in my projects, I think I'm missing something here.
Please help, any insight will do, thank you!

Hasuman

  • Playmaker Newbie
  • *
  • Posts: 19
Re: How to prepare things to be 'replaceable' and 'scalable'?
« Reply #1 on: May 19, 2019, 01:17:07 PM »
Aren't there actions for finding child objects by name? Maybe you could have the "master" object (usually the one that handles the main states and movement etc.) try to find an object by a certain name. Have a list of different named objects in a single frame state before starting anything else for that object. So let's say you can have an object "PistolMesh" inside of the master object, or "ShotgunMesh", so have a state where it checks for both of those and then adds it into an object variable. Then send all actions into the variable, and not the object specifically.

At least that's kinda what I'm doing for my player. I set the model into a variable instantly when it spawns so I can easily replace it if it becomes necessary, or if the mesh breaks during re-import and has to be replaced.

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: How to prepare things to be 'replaceable' and 'scalable'?
« Reply #2 on: May 19, 2019, 01:25:18 PM »
I don’t know the best way, but something I do and which works for me.

Adopt a mindset where everything not static can be spawned at runtime. So when a game object needs any reference, it can never rely on it being hardwired into it.

Internal Reference
All internal references to other game objects within the own hierarchy can be handled in two ways:

1) use the Start state as initialisation (ini) state that is only used once on actual start, and the functionality of the FSM never goes back to it. In this state, you can Set GameObjects explicitly into variables, and from then only use those variables. By making it this way, you can always view the Ini state and set it up correctly. You can also refactor easily and have the game object found by tag (though this is regarded as expensive. Doing it on once start should be no problem). Don't use find by name, because that can easily break.

2) Use the category field in variables and mark variables as "Ini" to be set when setting up the new prefab (variant etc). I also use Config and Runtime as recurring categories that make clear what is configurable (like running speed) and what shouldn't be touched as it's handled by the game. This is the same thing as above, only that you set defaults into the "ini" variables right away. I suggest that you at least make game object null check at start to tell you quickly and easily when you forgot this.

Broadcasting
Try to architect with elements that are ignorant of each other. For example, the health FSM can broadcast to all inside the player that it took damage and not care at all about anything else. Another FSMs gets triggered through the broadcast event and updates the UI, another one plays the FX and sounds and so on. None need to care who send the event and why. If the FX FSM is missing, you have no problems except that simply the FX are missing, but no errors. Make sure that such events aren’t spammed from random directions in random order. There should be one sender and a number of listeners subscribed to it.

Singleton Style
Instead of a game object finding other objects in the scene, you can try a singleton style approach. You make one game object, a “manager” and pay extra attention that it always exists in the scene, and that it can only exist once and once only (else, your game breaks!). Next, newly spawned entities can inscribe themselves to the manager’s variables. Because the manager exists once, you can easily find it with a tag. The player, upon spawning, can look for the manager and can set itself into the manager’s playerGameObj variable. You can also combine it with the previous idea, and broadcast an event, and the manager listens. When it hears the player spawned, it can get the event info and set the game object variable.

I hope you get the idea.  :)
« Last Edit: May 20, 2019, 06:08:46 AM by Thore »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: How to prepare things to be 'replaceable' and 'scalable'?
« Reply #3 on: May 19, 2019, 05:26:26 PM »
Hi.
Singleton Style is indeed a good way to go.

Another thing i tend to do a lot when building player/enemies is :

Have an Empty parent which would hold a rigidbody(if needed), a collider (again if needed) and most fsms.

Then inside the parent i have the mesh or sprite, with its animator (if needed)
And other objects if needed

On the fsms i use a variable to reference the object with the animator.

Now if you would change the mesh object with another, you only need to set it to the reference variable and nothing should break :)

rechronicle

  • Full Member
  • ***
  • Posts: 119
  • Mystvaldia
    • Indie RPG Creator
Re: How to prepare things to be 'replaceable' and 'scalable'?
« Reply #4 on: May 20, 2019, 11:35:22 AM »
Hello,
Thank you so much for the answers, everyone!

Some things are completely new to me so it's really helpful to learn in other perspectives.

To summarize things:
- Use parent & child object to separate script and mesh so it can be tweaked.
- Init and put things in a variable so it can be referenced.
- Use "metadata" and make it a singleton.
- The broadcast architect that's ignorant of each other.
CMIIW


One question, is there anything that I need to prepare so the animator can be playing in synergy with, for example, player controller FSM?
I have tried using 'Get FSM State' on dedicated animator FSM to listen from 'PlayerMovement.FSM' but it doesn't do well because most of the states are executed almost instantly.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7614
    • jinxtergames
Re: How to prepare things to be 'replaceable' and 'scalable'?
« Reply #5 on: May 20, 2019, 05:19:43 PM »
Hi.
It depends a bit on your setup.

For example for movement you can get the axis and set this to a animator variable (every frame).
Then on the animator use some conditions to set Idle/Walk/Run animations.

The dedicated animator fsm is good for (for example) to play certain sounds