MixedRealityToolkit-Unity icon indicating copy to clipboard operation
MixedRealityToolkit-Unity copied to clipboard

Adding and configuring components like BoundingBox, ManipulationHandler at runtime?

Open mtaulty opened this issue 7 years ago • 6 comments

Overview

Adding a behaviour like BoundingBox or ManipulationHandler to an object in the designer seems pretty good - I can simply drag/drop and then I can change 'properties' such as BoundingBox.activation or ManipulationHandler.allowFarManipulation.

However, I am creating objects dynamically and adding these behaviours from code and I find that the various properties that I need to set to 'configure' the behaviour are all private fields.

Is this by design or am I just missing the right way to do this? In the previous toolkit scripts like TwoHandManipulatable.cs had public access to properties to change behaviour when dynamically adding the script and I was making use of them.

Expected Behavior

I'd like to be able to add components like BoundingBox, ManipulationHandler and there could perhaps be others dynamically to an object created at runtime.

If the fields were protected, I could just derive and I'd be happy with that but, right now, they are private.

Actual Behavior

I don't seem to be able to dynamically change much on these types if I have added them through code rather than through the editor.

Steps to reproduce

N/A

Unity Editor Version

2018.3.11f1

Mixed Reality Toolkit Release Version

2.0.0-RC1

mtaulty avatar Apr 12 '19 08:04 mtaulty

It's certainly not the case that these should be less accessible than the versions in the htk, although some patterns might have changed slightly. Will try and look later.

@cre8ivepark any thoughts why the access pattern might have changed

SimonDarksideJ avatar Apr 12 '19 11:04 SimonDarksideJ

Similar problem here. I'm trying to add the interactable script dynamically and this gives me a null-reference-exception in the Update-Method, because the StateManager is not initialized. It seems like you have to do a lot of manual configuration. That's fine, however as @mtaulty mentioned, most of the fields are private.

Steps to reproduce

You can simulate this behaviour, by adding the component manually via the editor while in play-mode.

simmue avatar Apr 16 '19 07:04 simmue

I'd like to be able to add components like BoundingBox, ManipulationHandler and there could perhaps be others dynamically to an object created at runtime. If the fields were protected, I could just derive and I'd be happy with that but, right now, they are private.

All ManipulationHandler fields should now be publicly settable as of #4181. #4181 also made ManipulationHandler addable and configurable at runtime (there is a Playmode Test to verify that ManipulationHandler can be added at runtime).

julenka avatar May 16 '19 04:05 julenka

Looks like the remaining work is to verify that bounding box can be added programmatically, and configured programatically.

julenka avatar May 16 '19 04:05 julenka

I'm trying to add the interactable script dynamically and this gives me a null-reference-exception in the Update-Method, because the StateManager is not initialized.

This will be fixed by #4391

julenka avatar May 16 '19 04:05 julenka

I've started on this in branch https://github.com/julenka/MixedRealityToolkit-Unity/tree/bbox

Test files: BoundingBoxTest.zip

julenka avatar May 16 '19 07:05 julenka