playMaker

Author Topic: Changing player characters  (Read 1383 times)

Fearinhell

  • Playmaker Newbie
  • *
  • Posts: 8
Changing player characters
« on: November 01, 2021, 10:12:27 AM »
I would like to be able to change the player avatar at different times with code.  Lets say I have two characters and one is toggled off.  I have the code and everything setup to switch except for what I have circled in red in the photo in playmaker.  I have two of those items each aimed for a different avatar, how do I in C# disable the first avatar and enable the second?  Thanks in advance.

Fearinhell

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Changing player characters
« Reply #1 on: November 01, 2021, 08:35:40 PM »
I got it, I was making that harder than it should be.  I just went higher up in the hiearchy.

Fearinhell

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Changing player characters
« Reply #2 on: November 08, 2021, 04:53:53 PM »
Nope I need this to work like originally thought so my work around is no good.  Help needed again for original question. 

Nacho100

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Changing player characters
« Reply #3 on: November 09, 2021, 02:56:32 PM »
Hi, if I didnt understand wrong what you need is the action Enable Character Controller. Put in both characters the Character controller but turn on and off when you change between them (and move the camera if you need).

Hope it helps! If it didnt I'll try to explain better  :)

Fearinhell

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Changing player characters
« Reply #4 on: November 09, 2021, 04:54:42 PM »
I think so but how do I toggle it on/off when switching the  characters?  What would be an example of a C# code for that?  Thanks!

Fearinhell

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Changing player characters
« Reply #5 on: November 10, 2021, 09:55:12 AM »
I also need to do this for the animator object.  I have 33 characters Im wanting to switch back and forth from so was hoping to create an array or something to streamline this process but Im a coder not a playmaker person so this transition has been challenging for me.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7621
    • jinxtergames
Re: Changing player characters
« Reply #6 on: November 10, 2021, 10:42:58 AM »
Hi.
I am not sure what you mean.

Maybe the action "Activate Component" ()is what you are looking for?
Another possibility is "Acitvate GameObject"

You can also make custom actions, maybe the Playmaker API can help

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Re: Changing player characters
« Reply #7 on: November 10, 2021, 12:49:55 PM »
you can also toggle the "mesh renderer" enabled property with set property

Fearinhell

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Changing player characters
« Reply #8 on: November 10, 2021, 03:03:16 PM »
Ok Im already toggling the mesh renderer off since it it attached to the parent object.  I cant have 30 of those animators running at the same time here.  I need to find a way to toggle from Animator1 animator2 animator3 to animator32 when the parent object becomes active.  Im looking into maybe the visibility / invisible action trigger Im just trying to learn playmaker as a complete newb.  Ive been watching the tutorials just stuck with how to turn on these action states. 

Fearinhell

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Changing player characters
« Reply #9 on: November 11, 2021, 12:34:12 PM »
Let me try this again Im not explaining myself well enough.  I have 32 characters I want to switch between in runtime, the controller Im using requires these states on the right side.  I cant have 32 animator states running at once, I need to be able to toggle these on one at a time as that character is made active.  Here is another photo, thanks in advance.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7621
    • jinxtergames
Re: Changing player characters
« Reply #10 on: November 11, 2021, 03:18:08 PM »
Hi.
Sorry but im still unclear of what you mean.

Maybe place characters into an array, then use array get with the index and store in a variable and then use that on the set gameobject.

Fearinhell

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Changing player characters
« Reply #11 on: November 12, 2021, 09:24:25 AM »
Yes the array is the next step.  I was finally successful in getting this to work.  But from what I could see and find you cant enable/disable a state of an FSM during runtime?  I found some old articles on here from 2016 era that you cant do it.  So I was able to put a character controller on the parent object all of the childs aka actual avatars Ive built on.  Then I disabled the controllers on them.  This has lead to the asset not being able to run but I was wanting to remove that so that works.  Then I had to get the camera to move with the character again and in the end that was a very simple line of code,
Compass.transform.SetParent(Alli3T, false);

The issue was the animator controller had to be on the child object and change state objects, it isnt elegant but I was able to just copy this assets fsm and place it on each child object and it running on both the parent and the child I can now toggle between characters.  There was something else minor I had to change but cant recall.  But it works!  Now to just move it all over to an array so I can have multiple of these avatars without taking up pages of code.  Thanks for the help. 

This is the states Im referring to changing
https://hutonggames.com/playmakerforum/index.php?topic=12403.0

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7621
    • jinxtergames
Re: Changing player characters
« Reply #12 on: November 16, 2021, 08:46:23 PM »
Hi.
Disabling actions/states during runtime is not possible indeed, but you can use templates and use 'Run Fsm' on the template on the start state add a Bool Test and expose the variable.
on the fsm where you have this run fsm, you can now set that bool. from some other fsm.

this way it will only work when the bool is changed before entering the state.

if you want this to work any time then on the run fsm use a Fsm Bool Test (Ecosystem)
expose the target gameobject (owner might not work on a run fsm)