Parameterless struct constructors not available

Falxo 2 years ago updated by Lazlo Bonin (Lead Developer) 2 years ago 4

I was having trouble creating a flow that would be able to dynamically change the sources of a constraint in runtime, but it required input of a data type I had no idea about. It was simply called source and it wouldn't accept game objects as valid inputs as I initially thought.

So it baffled me as I was searching around to find a way to convert object targets into valid constraint sources. Keep in mind that I'm quite inexperienced with both Unity and Bolt.

After a while, I gave up and took to Bolt's Discord channel and got the help of the guru user "Reality.Stop()" who pointed out to me that I should create the needed units manually by going Bolt's Unit Options Wizard, add "Constraint Source" to the Type Options section and regenerate units to get some extended support for this type of data.

To some extend, it worked as I was now given a few extra units to handle such data, but nothing to create a "Constraint Source" struct.

Later on, the same user found out that said struct was simply Transform and weight data and simply made an extension to allow me to create it manually within a flow. Many thanks to him, it works flawlessly.

All you have to do is include the script in your project, regenerate units and it should appear in your available units.

using Ludiq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Animations;
    // This script was originally created and provided by Bolt's community member "Reality.Stop()".
    public static class ConstraintSourceExtension
        public static ConstraintSource CreateConstraintSource()
            return new ConstraintSource();
        public static ConstraintSource CreateConstraintSource(Transform target, float weight)
            return new ConstraintSource() { sourceTransform = target, weight = weight };

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):
Satisfaction mark by Falxo 2 years ago
Working on Fix

Thanks for the in-depth report!

I'll mark this for fixing ASAP, it's a core issue. I think the underlying problem is that structs don't have parameterless constructors per se at the IL level, so Bolt doesn't pick them up when analyzing your codebase. I'll have to add some kind of exception case for those at the reflection API level.

Fixed in Next Version

Was a bit more involved than I thought, but got it done for v.1.4.0f6.

All structs now support parameterless constructors. 99% of the time it's useless because structs should be immutable, but the C# language allows it, so should Bolt!