Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question C# code to add ScaleConstraint component?

Discussion in 'Scripting' started by Owyn_, Oct 3, 2023.

  1. Owyn_

    Owyn_

    Joined:
    Oct 3, 2023
    Posts:
    3
    upload_2023-10-3_23-3-42.png
    I can add all other components just fine but for Constraints it errors - what am I doing wrong?
     
  2. orionsyndrome

    orionsyndrome

    Joined:
    May 4, 2014
    Posts:
    3,043
    Hmm, this could be something in relation to covariance and contravariance, can't really tell.

    Basically, ParentConstraint derives from Behaviour, which itself derives from Component, so it's definitely a component.

    And what you're doing seems fine, I've seen examples with PositionConstraint elsewhere, nothing extraordinary about it.

    We need more details about what you're doing, for example have you added
    using UnityEngine.Animations;
    at the top of the file?

    And also, it's not a valid thing to try add any component to a prefab. Is that an instance copy of the prefab instead?
     
  3. Owyn_

    Owyn_

    Joined:
    Oct 3, 2023
    Posts:
    3
    Yes I have the `using` and a dll reference for animations,
    I"m writing a plugin for a unity game, - could it be that that part of the unity is cut out from the final game build and that's why it's missing constraints? Even thought the unity version used should have them
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,713
    Not so much that but doesn't that new Animations constraint stuff live in a package??

    That package would not normally be in UnityEngine.dll ... is that the assembly you are using to reference?
     
  5. Owyn_

    Owyn_

    Joined:
    Oct 3, 2023
    Posts:
    3
    I'm using `
    <Reference Include="UnityEngine.AnimationModule">
    <HintPath>...\UnityEngine.AnimationModule.dll</HintPath>
    </Reference>`

    But still some stuff seems to be missing, e.g. https://docs.unity3d.com/ScriptReference/Animations.ConstraintSource.html is not defined anywhere
     
  6. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    328
    Are you adding the reference in Visual Studio (in the .csproj file)? This won't work as Unity (for now) does not use references from .csproj, you need to manually copy the DLL in the Assets folder of your Unity project.

    Or if it's a Unity package, just install it and Unity will take care of copying/referencing the necessary DLLs.
     
    Last edited: Oct 5, 2023
    orionsyndrome and Bunny83 like this.