0
Answered

Marker Position when clicking a game object into a global variable Save

markusrgb 5 months ago in Game Creator updated 5 months ago 3


Hello, everyone,

maybe one of you could help me out.

I need a way to store the transform data of a marker when clicking on a parent game object in a global variable.

Unfortunately I could not find a solution for this yet.

There are several ways to find a component in a GameObject (using "strings") or to count the number of children.

There is also the possibility to address a child directly via the index.

But I could not generate a solution for my problem because I don't know the index when I click on it.

The structure of the game objects usually looks like this :

Parents (GameObject)

Child (Action or Condition)

Child (marker)

Child (...)

Unfortunately it is not always guaranteed that the marker is on a certain index position.

It would be optimal if I could search all children of a game object -> then find the marker -> and then store the transform component in a global variable.

Maybe you have a hint for me how I can solve this.

Thanks a lot

Markus

Unity version:
2019.3.11f1
Game Creator version:
1.1.6

not that you're giving me the wrong idea:

I know that within a game object -> with trigger "on Click ..." -> Action -> I can assign a game object (marker) to a global variable.

But in my case I pass the "Parent Game Object" in form of a Global Variable to an "Action Script" which is directly attached to the player. This action should then query whether a marker is available based on the parent data and then determine its position.

Answered

I believe you'll need to use a custom Action for this case, which is quite particular. You can set this Action to store the Marker object found in its children using the following code:

NavigationMarker marker = parentObject.GetComponentInChildren<NavigationMarker>();
GlobalVariables.SetGlobal("your-global-var-name", marker.gameObject);

Hope this helps.

Hi, Marti,

thanks for the tip with the Custom Action and Conditions.

I had found this possibility before in your documentation:

https://docs.gamecreator.io/game-creator/systems/game-creator-api

Unfortunately I am not a programmer and despite the code you gave me I have no idea how to implement it.

;)

Markus