Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How to Setup ISimulatable Interface/MarsTime Specific Functions?

Discussion in 'Unity MARS' started by harold_unity365, Jun 9, 2020.

  1. harold_unity365

    harold_unity365

    Joined:
    Jun 9, 2020
    Posts:
    3
    Hi!

    So here's a sample situation to explain my question

    I am trying to make a sphere proxy bob up and down in place over its surface target via script, and i want it to work in the simulator

    I've written a script that creates a scalable sin wave shaped movement pattern that can be applied to any of the transform axes:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Unity.MARS;
    5.  
    6.  
    7. public class ObjectCycleForce : MonoBehaviour, ISimulatable{
    8.  
    9.     public bool runInEditMode;
    10.  
    11.     public float speed = 1.0f;
    12.     public float XFactor = 0.0f;
    13.     public float YFactor = 0.0f;
    14.     public float ZFactor = 0.0f;
    15.  
    16.  
    17.     // Update is called once per frame
    18.     void Start(){
    19.        
    20.     }
    21.     void MarsUpdate()
    22.     {
    23.         float wavePos = Mathf.Sin(MarsTime.Time*speed);
    24.         float XOutput = (wavePos - 0.5f) * XFactor;
    25.         float YOutput = (wavePos - 0.5f) * YFactor;
    26.         float ZOutput = (wavePos - 0.5f) * ZFactor;
    27.         Vector3 outputPosition = new Vector3(XOutput, YOutput, ZOutput);
    28.         transform.position = outputPosition;
    29.     }
    30. }

    It may lbe complete nonsense i honestly haven't messed with spawn pools so maybe the documentation is more obvious to someone who has. I managed to run this without errors, however, the object that this is attached to stays static. Running the script on an object without the mars specific code yields the movement i expected.

    The spheres generated in a build on my android testing device, not on the simulator, are static as well regardless of if I implement the mars time stuff or not. A simple example skeleton of an object script would be huge.

    I know the webinar is tomorrow, do you imagine the instructor will be touching on scripting? or am i going about this in the wrong way and should be using an animator for any motion of spawned objects, especially in simulator.
     
  2. harold_unity365

    harold_unity365

    Joined:
    Jun 9, 2020
    Posts:
    3
    Update: switching up the functions to use basic Time.time and Update() and serializing each of the input fields made the cycle function work on my testing device, but obv no love in the simulator.
     
  3. amydigiov_Unity

    amydigiov_Unity

    Unity Technologies

    Joined:
    May 24, 2016
    Posts:
    16
    Hi @harold_unity365, MarsUpdate is not quite the same as Update - it is not called automatically for classes that implement ISimulatable. MarsUpdate is an event in the static class MarsTime. I would suggest adding the following to your original script:
    Code (CSharp):
    1. void OnEnable()
    2. {
    3.     MarsTime.MarsUpdate += MarsUpdate;
    4. }
    5.  
    6. void OnDisable()
    7. {
    8.     MarsTime.MarsUpdate -= MarsUpdate;
    9. }
    ISimulatable is only used to mark a MonoBehaviour as being "runnable" by Unity MARS in edit mode simulation. The runInEditMode member in ObjectCycleForce is not needed - runInEditMode is already a property in MonoBehaviour (https://docs.unity3d.com/ScriptReference/MonoBehaviour-runInEditMode.html). A MonoBehaviour that implements ISimulatable has this property set to true during edit mode simulation.

    Hope this helps!
    -Amy
     
    jmunozarUTech and wintermuute like this.