0
Answered

Copy from Object variable list to vector3 variable list

Niukeh 3 months ago in Game Creator updated by Marti (Lead Developer) 3 months ago 1

Hi, i can copy all the elements from a object list to another object list, using the loop list and add to list actions. but when the list is vector3 instead of gameobject list it throws this error.

What im trying to do is to when saving the game, also  save the position of certain objects spawned in the game world to respawn them all when loading the game. my aproach ( correct me if there is another way to do this)is to gather al the objects i want to save and put them on a object list variable just before the save game action executes. then loop the list and copy them all to a vector3 variable list with  saved cheked. Then on load loop the entire list instantiating all the objects again.

Thank you !  

InvalidCastException: Specified cast is not valid.
GameCreator.Variables.Variable.Update (System.Object value) (at Assets/Plugins/GameCreator/Variables/Mono/Types/Variable.cs:147)
GameCreator.Variables.Variable.Set (GameCreator.Variables.Variable+DataType type, System.Object value) (at Assets/Plugins/GameCreator/Variables/Mono/Types/Variable.cs:135)
GameCreator.Variables.Variable..ctor (System.String name, GameCreator.Variables.Variable+DataType type, System.Object value, System.Boolean save) (at Assets/Plugins/GameCreator/Variables/Mono/Types/Variable.cs:78)
GameCreator.Variables.ListVariables.Push (System.Object value, System.Int32 index) (at Assets/Plugins/GameCreator/Variables/Mono/Components/ListVariables.cs:78)
GameCreator.Variables.ListVariables.Push (System.Object value, GameCreator.Variables.ListVariables+Position position, System.Int32 index) (at Assets/Plugins/GameCreator/Variables/Mono/Components/ListVariables.cs:110)
GameCreator.Variables.ActionListVariableAdd.InstantExecute (UnityEngine.GameObject target, GameCreator.Core.IAction[] actions, System.Int32 index) (at Assets/Plugins/GameCreator/Variables/Mono/Actions/ActionListVariableAdd.cs:26)
GameCreator.Core.IAction.InstantExecute (UnityEngine.GameObject target, GameCreator.Core.IAction[] actions, System.Int32 index, System.Object[] parameters) (at Assets/Plugins/GameCreator/Core/ScriptableObjects/Interaction/IAction.cs:21)
GameCreator.Core.IActionsList+d__9.MoveNext () (at Assets/Plugins/GameCreator/Core/ScriptableObjects/Interaction/IActionsList.cs:107)
UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) (at <7d22f8e71133418c87c7b26ea181f3e3>:0)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
GameCreator.Core.IActionsList:Execute(GameObject, Action, Object[]) (at Assets/Plugins/GameCreator/Core/ScriptableObjects/Interaction/IActionsList.cs:91)
GameCreator.Variables.d__8:MoveNext() (at Assets/Plugins/GameCreator/Variables/Mono/Actions/ActionListVariableLoop.cs:80)
GameCreator.Core.d__3:MoveNext() (at Assets/Plugins/GameCreator/Core/ScriptableObjects/Interaction/IAction.cs:34)
GameCreator.Core.d__10:MoveNext() (at Assets/Plugins/GameCreator/Core/ScriptableObjects/Interaction/IActionsList.cs:29)
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
GameCreator.Core.ActionCoroutine:.ctor(IEnumerator) (at Assets/Plugins/GameCreator/Core/ScriptableObjects/Interaction/IActionsList.cs:24)
GameCreator.Core.d__9:MoveNext() (at Assets/Plugins/GameCreator/Core/ScriptableObjects/Interaction/IActionsList.cs:109)
UnityEngine.SetupCoroutine:InvokeMoveNext(IEnumerator, IntPtr)

Unity version:
Game Creator version:

Answer

Answer
Answered

Seems like you're trying to cast a game object onto a Vector3. This is not permitted. Instead, you need to access the position (I guess you want to store the position of the game objects):

[gameobjectFromVariable].transform.position

Hope this helps!

Answer
Answered

Seems like you're trying to cast a game object onto a Vector3. This is not permitted. Instead, you need to access the position (I guess you want to store the position of the game objects):

[gameobjectFromVariable].transform.position

Hope this helps!