C# export variables not working even after building.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By The Glitch

Exactly what the title says, can get C# export variables working even after building and restarting the editor. I have correct syntax and it only is broken on one file.

Without source, nobody can give your advice. Export variables are an obvious features; perhaps there’s some other syntax error in this one file?

spaceyjase | 2023-03-09 13:15

correct syntax and it only is broken on one file.

what is broken? why is broken? why you left broken?

Moreus | 2023-03-09 14:02

Here is my code:

Sorry for my spaghetti code

using Godot;

using System;

public partial class Ball : CharacterBody2D
{
[Export]
public const float Speed = 100.0f;
[Export]
public const float SpeedUp = 20.0f;

private Vector2 VectorDelta = new Vector2();

//Initial Pos var
private Vector2 InitialPos;
//Random Angle
private float Angle;

public override void _Ready()
{
    Angle = GetAngle();

    Velocity = Vector2.Left.Rotated(Angle) * Speed;

    //Set the reset location
    InitialPos = Position;
}

public override void _PhysicsProcess(double delta)
{
    //Handle Bounce
    VectorDelta = new Vector2((float)delta, (float)delta);

    var CollisionInfo = MoveAndCollide(Velocity * VectorDelta);
    if (CollisionInfo != null)
    {
        Velocity = Velocity.Bounce(CollisionInfo.GetNormal());
    }

    //Move And Slide
    MoveAndSlide();
}

private void IncreaseSpeed()
{
    if (Velocity.X > 0)
    {
        Velocity = Velocity + new Vector2(SpeedUp, 0);
    } else if (Velocity.X < 0)
    {
        Velocity = Velocity - new Vector2(SpeedUp, 0);
    }

    if (Velocity.Y > 0)
    {
        Velocity = Velocity + new Vector2(0, SpeedUp);
    }
    else if (Velocity.Y < 0)
    {
        Velocity = Velocity - new Vector2(0, SpeedUp);
    }

}

public void _OnPaddleDetectorBodyEntered(Node2D body)
{
    if (body.IsInGroup("Paddle"))
    {
        IncreaseSpeed();
    }
}

private void _Reset()
{
    Angle = GetAngle();
    Position = InitialPos;

    Velocity = Vector2.Left.Rotated(Angle) * Speed;
}

private float GetAngle()
{
    int Rand;

    while(true)
    {
        Rand = GD.RandRange(0, 1);

        if (Rand == 0)
        {
            return Mathf.DegToRad(-1);
        } else
        {
            return Mathf.DegToRad(1);
        }
    }
}

}

The Glitch | 2023-03-10 19:30

I don’t really see anything wrong and it runs fine

The Glitch | 2023-03-10 19:31

:bust_in_silhouette: Reply From: Moreus

I suspect You cannot change const this why you will not export, and
If you use big letter you should use properties with getter and setter

[Export]
public float Speed { get; set; } = 100.0f;
[Export]
public float SpeedUp { get; set; } = 20.0f;

or small
[Export] public float speed = 100.0f; [Export] public float speedUp = 20.0f;