+3
Completed

Instantiate object / set exposed fields

joshrmt 4 years ago updated by Lazlo Bonin (Lead Developer) 3 years ago 9

Is there a way to easily set an object's properties/fields in a manner similar to the 'expose fields' unit?  Basically, I need an 'expose fields' feature which provides inputs rather than just outputs.  I need to instantiate objects/components with a lot of properties, and the only way I can find to do this is to use a sequence and create a 'Set <property>' unit for each property.  This is extremely cumbersome and time-consuming.

I could create this unit myself if I could figure out how to define dynamic inputs, but I haven't had time to dig through the source code yet to figure out how expose fields works.

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):
Pending Review

Hi Josh! Welcome to the community :)

Interesting idea! I'll keep it in mind for the future.

So then I guess the answer is 'no'?  I'm a savy developer, is there a way I could implement it myself?

The answer is definitely not no, or I would have labeled it as declined. It's just that the roadmap is tightly packed right now, so I cannot plan or guarantee that this feature will get implemented any time soon.

I don't provide support for creating custom units by script yet, but if you want, here's the source for the expose unit: https://pastebin.com/g1HwD926

Also, is there a way to define a 'unit' from just a C# class?  I recognize that you leverage reflection to expose class libraries, but I want to control the input/output ports from code.  Other flow-based frameworks I use offer this functionality.

There is a way, by extending the Unit class, but there is no support or documentation for that at the moment.

Thanks, I just want to make sure there is a way without too much hacking on my part.  I don't mind reading through source code to expand functionality.  If you were to make it easy for developers to map their own C# classes to units, I think this tool would become significantly more powerful and viable for the 'pure-developer' crowd.  Reflected units tend to become cumbersome for developers that need stronger control over the data-flow, particularly when it comes to asynchronous or long-running routines.

I appreciate your replies!  I'm excited about the potential of this product, despite the fact that I generally do not use visual programming tools.

C# classes to units

If you aren't using a Mono, you can use a default constructor in the class.  This will generate a "New ClassName" unit, and any parameters in the constructor will show up as inputs.  Make sure to add the class to Types in the Unit Update Wizard.  Of course, this is less useful if you are modifying an existing object.

Another workaround is to simply create a method in the class and use that method unit to handle your setup.  Any method parameters will also show up as an input in the unit.

Finally, you can make a Super Unit with the appropriate inputs, and then do all of your stuff inside of the super unit.  From there you can just copy/paste the super unit wherever you need it.  If your code is modular, you can also just save it as a macro and drag/drop whenever you need it.

Super Unit Example:


+1
Completed

The new chainable set / invoke units in 1.4 should address this request!