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

Resolved Set VisualElement's % based position with c#

Discussion in 'UI Toolkit' started by xOrfe, Apr 25, 2023.

  1. xOrfe

    xOrfe

    Joined:
    Apr 21, 2013
    Posts:
    31
    I cant figure out how can i set % based position with c# as in the UI Toolkit window. Any idea?
    upload_2023-4-25_10-6-20.png
     
  2. SimonDufour

    SimonDufour

    Unity Technologies

    Joined:
    Jun 30, 2020
    Posts:
    515
    You create percentage using
    style.width = Length.Percent(100);


    There is an implicit cast to a length as pixels when you assign a number to a styleLength, so you need to be explicit by using Length.Percent or by using the constructor with the unit specified to have a percentage.
     
    xOrfe likes this.
  3. xOrfe

    xOrfe

    Joined:
    Apr 21, 2013
    Posts:
    31
    Thank you so much <3