edited December 2017 in ORK Scripting
I am trying to initialize Status values for my player through a script and I'm trying to do it as soon as the Player is Spawned.
Once the player is spawned, I get an instance of the Combatant class in the Spawned GameObject through "Component Helper" and initialize the status values using,


using UnityEngine;
using ORKFramework;
using ORKFramework.Behaviours;

public class AssignStatus : MonoBehaviour
{
public void InitSPECIALS()
{
Combatant playerCombatant = ComponentHelper.GetCombatant(GameObject.FindGameObjectWithTag("Player"));

for (int i = 0; i < SPECIALS.specialValues.Length; i++)
{
playerCombatant.Status[i].InitValue(SPECIALS.specialValues[i]);
}
Debug.Log("Called!");
}
}


However, when I log the above function, It seems it is not executed at all and the status values stay the same.I think i am doing something wrong with the "Target Object" Field in the "Call Function" Node.

I tried making the function "InitSPECIALS" Static to avoid the Target Object, and it Worked!

So What does Target Object mean?

Also, I get this weird warning every time, I spawn my player:

Parent of RectTransform is being set with parent property. Consider using the SetParent method instead, with the worldPositionStays argument set to false. This will retain local orientation and scale rather than world orientation and scale, which can prevent common UI scaling issues.
UnityEngine.Transform:set_parent(Transform)
ORKFramework.Behaviours.EventInteraction:DontDestroy()
ORKFramework.Events.BaseEvent:DontDestroy()
ORKFramework.Events.GameEvent:ChangeScene(SceneChanger, Int32)
ORKFramework.Events.Steps.LoadSceneStep:Execute(BaseEvent)
ORKFramework.Events.GameEvent:ExecuteNextStep()
ORKFramework.Events.BaseEvent:StartEvent()
ORKFramework.Events.GameEvent:StartEvent(IEventStarter, Object)
ORKFramework.Behaviours.d__29:MoveNext()
UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator)
ORKFramework.Behaviours.EventInteraction:StartEvent(GameObject)
ORKFramework.Behaviours.BaseInteraction:UIStart(GameObject)
ORKFramework.Behaviours.BaseInteraction:UIStart()
UnityEngine.EventSystems.ExecuteEvents:Execute(GameObject, BaseEventData, EventFunction`1)
ORKFramework.Behaviours.ORKInputModule:ProcessMousePress(MouseButtonEventData)
ORKFramework.Behaviours.ORKInputModule:ProcessMouseEvent(Int32)
ORKFramework.Behaviours.ORKInputModule:ProcessMouseEvent()
ORKFramework.Behaviours.ORKInputModule:Process()
UnityEngine.EventSystems.EventSystem:Update()

Thank You!

EDIT:

Also are the status values preserved between scenes? For Example, if I load a game from a save file should I save the player status values and reassign them every time?

Post edited by LemurusBalok on
  • Target object has to be the game object that has the component attached. The function not being called is probably due to the component not being found on the game object.
    If the function you call doesn't need any settings on the component itself, you can just make it a static function and call that :)

    You can ignore the warning for now. Your use case (calling a game event on a new UI game object) wasn't even there when this was written - will update it in the next update, but it doesn't do any harm.

    Status values of combatants in your player group are naturally preserved between scenes. Wouldn't make much of a game if they wheren't :)
    Other combatants (e.g. enemies spawned in the field) will only be stored when you set them to be in their combatant spawners.
    Please consider rating/reviewing my products on the Asset Store (hopefully positively), as that helps tremendously with getting found.
    If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Sign In or Register to comment.