In the documentation is says that the Alembic can be controlled via Timeline, Animation or script:
Because of the way that our timeline works (i.e. being stretched an contracted to accomodate the changes in duration) we don’t want to be using Timeline or animation, we want to do it via script (Controlling Alembic playback | Alembic | 1.0.7).
You can see here that the link for the scripting page has been unlinked. The ‘AlembicStreamPlayer’ (the component used to control the alembic animation) has a ‘Time’ parameter which would allow us to move the animation along in time with everything else happening in the system quite easily if we were able to set it directly. Unfortunately when I tried to access this parameter I’m struggling to access it directly. From searching through the forums I found this response (https://bit.ly/2INPF7N) from vladala at Unity:
The code that they refers to here provides a way to extract the current time out of the StreamPlayer but setting it doesn’t seem to work.
I can certainly try using the timeline and compensate for the duration etc but it will likely be a rather messy solution to what seems like it should be a relatively trivial problem.
To confirm, you tried doing prop.floatValue=12.0f and it does not work?
If you look in the thread you mentioned the next reply is another user that created some code to control the alembicStreamPlayer by reflection?
Hmm… Whilst this is working great in the editor, I’m having trouble building it for WebGL. I’m controlling the AlembicStreamPlayer (via the AlembicStreamController script) with my own script (AlembicAnimatable.cs), which works fine in the editor but when I build for WebGL I get the following erros which prevent it fromm building:
Assets\Scripts\Alembic\AlembicAnimatable.cs(5,19): error CS0234: The type or namespace name 'Formats' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)
and
Assets\Scripts\Alembic\AlembicAnimatable.cs(14,17): error CS0246: The type or namespace name 'AlembicStreamController' could not be found (are you missing a using directive or an assembly reference?)
it seems to be a problem finding the namespace for using UnityEngine.Formats.Alembic.Importer;
I’ve been doing a few experiments with a fresh project (so I can eliminate the possibility that it’s a conflit with something else in our codebase. I’ve found that I am able to build for webgl in a fresh project (without my AlembicAnimatable.cs script), but although it builds, the alembic objects are invisible.
Is the Alembic system maybe just not compatible with WebGL?
This is my AlembicAnimatable script btw:
(the #if !UNITY_WEBGL is just so I can get the rest of my codebase working as it is a primarily webgl based project)
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public class AlembicAnimatable : MonoBehaviour
{
//#if !UNITY_WEBGL
#region -- Variable Declaration --------------------------------------------------------------------------------
private UnityEngine.Formats.Alembic.Importer.AlembicStreamController controller;
private float Duration;
public Project currentProject;
public FloatVariable MasterTimelinePlayhead;
public FloatVariable TargetDuration;
#endregion -- End Variable Declaration -------------------------------------------------------------------------
#region -- Initialisation --------------------------------------------------------------------------------------
// Start is called before the first frame update
void Start()
{
controller = GetComponent<UnityEngine.Formats.Alembic.Importer.AlembicStreamController>();
Duration = controller.duration;
}
#endregion -- End Initialisation -------------------------------------------------------------------------------
#region -- Update & Animation ----------------------------------------------------------------------------------
void Update()
{
if (currentProject.focusedAsset)
{
SetPlayheadUpdate(MasterTimelinePlayhead.Value);
}
}
// Function to set the 'Time' value of the alembic animation
private void SetPlayheadUpdate(float value)
{
// Scale the anim in point relative to the master timeline
float animIn = currentProject.buildAnimationSettingsLocator.GetAnimIn() * 10;
if (MasterTimelinePlayhead.Value >= animIn)
{
// Calculate the start point of the animation relative to the scaled time
float startOnMaster = AA_Tools.RemapRangeClamped(animIn, 0, TargetDuration.Value, 0, 10);
// Calculate the end point of the animation relative to the scaled time
float endOnMaster = (Duration / TargetDuration.Value) * 10;
// Remap the timeline's value relative to the duration and offset by the start point so that animation plays at the correct speed
controller.time = AA_Tools.RemapRangeClamped(MasterTimelinePlayhead.Value, startOnMaster,
startOnMaster + endOnMaster, 0f, Duration);
}
else
{
controller.time = 0f;
}
}
#endregion -- End Update & Animation ---------------------------------------------------------------------------
//#endif
}
When I load the fresh project with the alembic in webgl I get these errors:
I’m wondering if its getting mixed up between the Editor and Runtime scripts perhaps?