Getting a variable with generics

Real World 3 years ago updated by Lazlo Bonin (Lead Developer) 3 years ago 3

I want to create a unit that gets a value from a dictionary. The dictionary is of type Dictionary<string,object> 

I'd like to create a Unit that takes a key as input and returns the value cast to a specific type. Is there some "generic" way I can do this to avoid having to create a wrapper for (int)MyDictionary["MyIntValue"] and (float)MyDictionary["MyFloatValue"] as separate units. A bit like how the Literal unit works I guess?

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

Are we talking about creating a unit through code or through a graph?

Either way, actually, even if your port outputs an object, Bolt can and will automatically convert it to its connected port (whether it's an int, float or otherwise) as part of the connection, behind the scenes. There's no need for an explicit cast operator (or node) like in C#.

I meant in code, yeah. I swear I tried it already and it wouldn't let me connect an object out to a bool input. Just written the code again and it works... magic :D