Skip to content

Actions extending an interface instead of abstract MonoBehaviour. #472

Open
@dreamora

Description

@dreamora

Problem

At this moment, it is impossible to use streaming levels, streaming prefabs or Addressables with VRTK because Actions extend from MonoBehaviour and are as such scene bound, making it impossible for the VRTK Setup to live anywhere but the same scene the prefabs using them exist in as the relationship is otherwise lost.

Proposed Solution

I would like to propose that Action instead of being an abstract MonoBehaviour, becomes an interface.
This would allow for the problem to be solved in simple, clean and scalable Dependency Injection approach where 2 kinds of actions can be implemented:

  1. Action (Local Actions): The same as they are now, extending MonoBehaviour. These actions are geared at handling relationship within the same prefab to provide the current degree of flexibility and possibilities.

  2. ActionSignal (Remote Actions): Using ScriptableObject as Action (Observer-Subscriber pattern) that is independent of the scene and specific game objects within it (explained in clean detail at https://www.raywenderlich.com/2826197-scriptableobject-tutorial-getting-started). Such actions could be used only as Source and Targets as serialized ScriptableObject asset can not hold scene dependencies, but at the same time they also ensure that no receiver of an action needs to know its sender or proxy sender.

Added benefit

This also addresses the current limitation of scene serialized coupling (cross prefab in scene dependency between the VRTK Setup, the interactions hierarchy and the actual interactable objects if we consider Farm as a baseline) by removing dependencies in the scene.
At the same time it makes it easier to design things if designers and developers have, for example, a single 'GrabActionSignal' they can use across the project.

Considered alternatives

  1. I looked into the possibility of cross scene references as outlined by the Unity Spotlight Team (https://blogs.unity3d.com/2018/07/19/spotlight-team-best-practices-guid-based-references). While it would offer a short term solution for certain cases, it would be incomplete and make the scene dependency issue more troublesome and hard to maintain.

  2. I looked into alternative ways along the path of code base Dependency Injection (Zenject/StrangeIoC) of key aspects like 'Main Interactions' (Grab, Use, ...) and the TrackedAliasFacade. While these would work for constrained situations. like getting global access to the tracking aliases, it is no scalable solution for the interaction side.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions