Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: serenefox on January 16, 2019, 04:15:26 AM
-
Hi community,
I am trying to write a bridge of sorts between Dungen and Playmaker assets.
I am trying to copy the array values from my script to the fsm array variable so I can work with it in playmaker. For some reason I can't figure out why the array values wont load into the playmaker fsm I have assigned in the inspector. Any help would be appreciated, Thanks!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DunGen;
using HutongGames.PlayMaker;
public class GetDoorPrefabsInTile : MonoBehaviour
{
public FsmArray pfsmArray;
public PlayMakerFSM DoorFunctionalityFSM;
public string nameOfArrayToWorkWith;
public Tile tile;
private GameObject[] PlaymakerFSMArray;
private void Start()
{
pfsmArray = DoorFunctionalityFSM.FsmVariables.GetFsmArray(nameOfArrayToWorkWith);
}
public void FindDoorPrefabs()
{
// Get the tile that you want somehow
GameObject[] tempArray;
int doorIndex = 0;
int Doorwaycount = tile.Placement.AllDoorways.Count;
tempArray = new GameObject[Doorwaycount];
// Loop through each used doorway in the tile - used doorways are those that are connected to other tiles
foreach (var doorway in tile.Placement.UsedDoorways)
{
// Only one door prefab is spawed per doorway-pair so it might be on this doorway, or it might be on the other
GameObject doorPrefab = (doorway.UsedDoorPrefab != null) ? doorway.UsedDoorPrefab : doorway.ConnectedDoorway.UsedDoorPrefab;
if (doorway.UsedDoorPrefab != null)
{
tempArray[doorIndex] = doorPrefab;
doorIndex++;
}
}
//doorIndex = 0;
pfsmArray.Values = tempArray;
}
}
-
Hi.
I can't test right now, but i do know you need to do something like fsmArray.saveChanges
fsmTarget.FsmVariables.GetFsmArray(arrayName.Value).SaveChanges();
-
Hello djaydino,
I tried adding your suggestion to my code but I am get this error:
Nested arrays are not supported yet!
UnityEngine.Debug:LogError(Object)
HutongGames.PlayMaker.FsmArray:Load(Int32) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmVariables/FsmArray.cs:251)
HutongGames.PlayMaker.FsmArray:SaveChanges() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmVariables/FsmArray.cs:339)
GetDoorPrefabsInTile:FindDoorPrefabs() (at Assets/_GameAssets/Scripts/GetDoorPrefabsInTile.cs:44)
System.Reflection.MethodBase:Invoke(Object, Object[])
HutongGames.PlayMaker.Actions.CallMethod:DoMethodCall() (at Assets/PlayMaker/Actions/ScriptControl/CallMethod.cs:98)
HutongGames.PlayMaker.Actions.CallMethod:OnEnter() (at Assets/PlayMaker/Actions/ScriptControl/CallMethod.cs:64)
HutongGames.PlayMaker.FsmState:ActivateActions(Int32) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:205)
HutongGames.PlayMaker.FsmState:OnEnter() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/FsmState.cs:175)
HutongGames.PlayMaker.Fsm:EnterState(FsmState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2768)
HutongGames.PlayMaker.Fsm:SwitchState(FsmState) (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2715)
HutongGames.PlayMaker.Fsm:UpdateStateChanges() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:2643)
HutongGames.PlayMaker.Fsm:Start() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/Classes/Fsm.cs:1926)
PlayMakerFSM:Start() (at C:/Projects/Playmaker_1.9.0/Projects/Playmaker.source.unity/Assets/PlayMaker/PlayMakerFSM.cs:548)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DunGen;
using HutongGames.PlayMaker;
public class GetDoorPrefabsInTile : MonoBehaviour
{
public FsmArray pfsmArray;
public PlayMakerFSM DoorFunctionalityFSM;
public string nameOfArrayToWorkWith;
public Tile tile;
private GameObject[] PlaymakerFSMArray;
private void Start()
{
pfsmArray = DoorFunctionalityFSM.FsmVariables.GetFsmArray(nameOfArrayToWorkWith);
}
public void FindDoorPrefabs()
{
GameObject[] tempArray;
int doorIndex = 0;
int Doorwaycount = tile.Placement.UsedDoorways.Count;
tempArray = new GameObject[Doorwaycount];
// Loop through each used doorway in the tile - used doorways are those that are connected to other tiles
foreach (var doorway in tile.Placement.UsedDoorways)
{
// Only one door prefab is spawed per doorway-pair so it might be on this doorway, or it might be on the other
GameObject doorPrefab = (doorway.UsedDoorPrefab != null) ? doorway.UsedDoorPrefab : doorway.ConnectedDoorway.UsedDoorPrefab;
if (doorway.UsedDoorPrefab != null)
{
tempArray[doorIndex] = doorPrefab;
doorIndex++;
}
}
//doorIndex = 0;
pfsmArray.Values = tempArray;
pfsmArray.SaveChanges();
}
}
-
Hey djaydino,
I finally got it to work. Thanks for your help. Apparently I am not able to assign the array value on start and I had to use the full line where I was saving them:
DoorFunctionalityFSM.FsmVariables.GetFsmArray(nameOfArrayToWorkWith).SaveValues();