Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Help me understand Behaviour System

Discussion in 'Project Tiny' started by EricksonCV, Jan 8, 2019.

  1. EricksonCV

    EricksonCV

    Joined:
    Oct 3, 2018
    Posts:
    1
    Hi guys, same one can help me in Unity Tiny, I created a method in a diferent Class and I called it into a Behavior class it doesn't work but I call the same method in another TypeScript System and he work in both I call in same way

    class whem I create the method increase Score
    Code (CSharp):
    1. namespace game {
    2.  
    3.  
    4.     export class GameService {
    5.         .
    6.    .
    7.    .
    8.  
    9.         static increaseScore(world: ut.World, context: game.GameContext) {
    10.             context.Score += 1;
    11.         }
    12.  
    13.    .
    14.    .
    15.    .
    16.     }
    17. }
    -------------------------------------------
    Call the method in Class Behavior( not work)

    Code (CSharp):
    1. namespace game {
    2.  
    3.     export class EnimyRectoBehaviorFilter extends ut.EntityFilter {
    4.  
    5.         entity:ut.Entity;
    6.         position: ut.Core2D.TransformLocalPosition;
    7.         tag:game.RectoTag;
    8.         speed:game.MovementSpeed;
    9.         speedChange:game.changeOverTime;
    10.         bounds:game.Boundaries;
    11.  
    12.     }
    13.  
    14.     export class EnimyRectoBehavior extends ut.ComponentBehaviour {
    15.  
    16.         data: EnimyRectoBehaviorFilter;
    17.            .
    18.    .
    19.    .
    20.      
    21.         // this method is called for each entity matching the EnimyRectoBehaviorFilter signature, every frame it's enabled
    22.         OnEntityUpdate():void {
    23.             let localPosition = this.data.position.position;
    24.             let context=this.world.getConfigData(game.GameContext);
    25.  
    26.            localPosition.x -= this.data.speed.speed * ut.Time.deltaTime();
    27.  
    28.            this.data.position.position = localPosition;
    29.  
    30.            if(localPosition.x <= this.data.bounds.minX){
    31.                 this.world.destroyEntity(this.data.entity);
    32.                 game.GameService.increaseScore(this.world,context);// execute the method whewm enimy Destroy
    33.             }
    34.  
    35.              
    36.          }
    37.    .
    38.    .
    39.    .
    40.  
    41.     }
    ------------------------------------------------
    I call the method in the system class (I put it without "if" just to see it works) work well

    Code (CSharp):
    1. namespace game {
    2.  
    3.     @ut.executeAfter(ut.Shared.UserCodeStart)
    4.     @ut.executeBefore(ut.Shared.UserCodeEnd)
    5.  
    6.     export class GameManagementSystem extends ut.ComponentSystem {
    7.      
    8.         OnUpdate():void {
    9.             let context=this.world.getConfigData(game.GameContext);
    10.  
    11.             game.GameService.increaseScore(this.world,context);
    12.      
    13.    .
    14.    .
    15.    .
    16.  
    17.         }
    18.     }
    19. }
    --------------------------------------------------
    Is there a diferent way to call a method in a behavior and what are the diferences between a behavior and a System
     
  2. vincismurf

    vincismurf

    Joined:
    Feb 28, 2013
    Posts:
    200
    A behavior is a system with a wrapper which provides callbacks for Enable/Disable and a build in filter.

    Personally I don't use the getConfigData() I would simply keep the score on the GameService

    I would
    1) put a console.log(); in the increaseScore() to make sure they are being called. ( It looks like it should)
    2) if it is being called perhaps the context is the problem.
    3) if the context is the problem, perhaps you have to "set" the configData
     
  3. etienne_unity

    etienne_unity

    Unity Technologies

    Joined:
    Aug 31, 2017
    Posts:
    102
    Side note about configuration components: use them instead of storing mutable data in system variables. This way you'll be able to see their content in the editor in play mode.
     
    ER_Dolleman likes this.