News Forums RAIN General Discussion and Troubleshooting Instantiate inside custom action?

This topic contains 5 replies, has 3 voices, and was last updated by  prime 1 month, 2 weeks ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #34965

    Simsure
    Participant

    My enemy, when it is close to the player, makes appear another object, so I used a custom action in the IA, in the Memory of the IA I set a variable as GameObject called “instrument” and I put the object that is to appear, then the custom action there is only this code.

    import RAIN.Action;
    import RAIN.Core;
    @RAINAction
    class attack_enemy extends RAIN.Action.RAINAction
    {
        function Start(ai:RAIN.Core.AI):void
    	{
            super.Start(ai);
    Instantiate(instrument,Vector3(transform.position.x+2, transform.position.y -9, transform.position.z-10) , transform.rotation);
    	}
        function Execute(ai:RAIN.Core.AI):ActionResult
    	{
            return ActionResult.SUCCESS;
    	}
    	function Stop(ai:RAIN.Core.AI):void
    	{
            super.Stop(ai);
    	}
    }

    But it gives me error

    Unknown identifier: “Instantiate”

    • This topic was modified 1 month, 3 weeks ago by  Simsure.
    #34967

    Astaror
    Participant

    Instantiate is a method of UnityEngine.Object class - which is parent of MonoBehaviour, and RAINAction is not a child of MonoBehaviour or any of Unity classes, so you can’t use Instantiate in it.

    But you can use it in following way: UnityEngine.Object.Instantiate, because it’s public static method

    • This reply was modified 1 month, 3 weeks ago by  Astaror.
    #34969

    Simsure
    Participant

    ok now works, thanks.
    But to call the variable that I set in “memory” I have to use this code right?

    AI.WorkingMemory.GetItem

    Then I did something like that.

    var instrument: GameObject;
    instrument = ai.WorkingMemory.GetItem<GameObject>("instrument ");

    But he says

    Assets / AI / Actions / enemy_attack.js (13,53): BCE0164: Can not infer generic arguments for method ‘RAIN.Memory.RAINMemory.GetItem. <T> (String)’. Provide stronger type information through arguments, or Explicitly been the generic arguments.

    • This reply was modified 1 month, 3 weeks ago by  Simsure.
    #34974

    prime
    Keymaster

    I believe the proper js syntax is

    instrument = ai.WorkingMemory.GetItem.<GameObject>("instrument");
    #34978

    Simsure
    Participant

    It gave me the error as ” transform” , I thought it was the same problem as before and I tried to solve it this way, I was right ?

    I do not think because nothing happens during the game !

    UnityEngine.Object.Instantiate(instrument,Vector3(UnityEngine.Object.transform.position.x+2, UnityEngine.Object.transform.position.y -9, UnityEngine.Object.transform.position.z-10) , UnityEngine.Object.transform.rotation);
    • This reply was modified 1 month, 3 weeks ago by  Simsure.
    #34995

    prime
    Keymaster

    You want something more like this:

    UnityEngine.Object.Instantiate(instrument,Vector3(ai.Body.transform.position.x + 2, ai.Body.transform.position.y - 9, ai.Body.transform.position.z - 10) , ai.Body.transform.rotation);
Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.