playMaker

Author Topic: Light Switch Prefab[SOLVED]  (Read 1880 times)

Bytor

  • Playmaker Newbie
  • *
  • Posts: 3
Light Switch Prefab[SOLVED]
« on: October 19, 2019, 11:24:39 AM »
I created a cube, set up a simple switch to control light intensity and material. I placed it over a light switch and it works perfectly. I then made it a prefab so I can just place it over other switches and simply adjust the game objects being affected. But no matter what I change it to, the initial light is the only one turning off and on. I hope this makes sense. Any help would be appreciated.
« Last Edit: November 13, 2019, 01:39:29 AM by jeanfabre »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Light Switch Prefab
« Reply #1 on: October 19, 2019, 04:29:07 PM »
Hi.
Can you show your fsm setup?
its hard to guess without some extra info :)

Bytor

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Light Switch Prefab
« Reply #2 on: October 19, 2019, 06:59:49 PM »
Like this?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Light Switch Prefab
« Reply #3 on: October 20, 2019, 08:31:12 AM »
Hi.

If i understand correctly, you made a prefab of the switch to turn on/off the light.

if so :

When you create a prefab, the connection to the Light Game objects will be lost (unless they would also be in the prefab)

Prefabs can not communicate directly with Scene objects (this is a unity limitation)

in your case you do not need to create these object  at runtime, so i would do something like this :

have one (empty) game object and call it for example 'Bathroom Light Handler'
have a fsm on it (Call it 'Light Switch' for example)

Make the same setup as on the image you send. except the mouse button down. (remove the action)
Also instead of On/Off Transition use a single transition name for both states (call it 'Flip Switch' for example.

Now on the 'Cube Switch' you will do the mouse event, but i beliebe the Action 'Get Mouse Button Down' will always trigger, even when not targeting the light switch.

So instead you can use 'Mouse Pick Event' and use the mouse down event to transition to the next state.
in the next state you can use 'Send Event By Name' and target the "Bathroom Light Handler" with the 'Flip Switch' transition.

From the 'Cube Switch' you can make a prefab.
But on the 'Send Event By Name' you will lose the target, so when you drag in a new prefab you will need to place the target in it.

The good thing is, you can use the same prefab for different rooms as well.
just make for example a "Living room Light Handler" and target that with the 'Cube Switch'

Here are some videos that can help :



Bytor

  • Playmaker Newbie
  • *
  • Posts: 3
Re: Light Switch Prefab
« Reply #4 on: October 20, 2019, 01:05:44 PM »
Thank you so much!