Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | CarlitosCUeba |
Actually, everything was fine until today, but for some reason the scene I was instantiating is returning null.
using Godot;
using System;
public class Bodyx : KinematicBody2D
{
//Atributos
private int ContadorTiro = 0;
//Movimentacao
private PackedScene BulletNode;
public override void _Ready()
{
BulletNode = GD.Load<PackedScene>("res://Body/Bullet.tscn");
}
protected void RetornoDirecao(int speed, Vector2 direcao, float delta)
{
MoveAndCollide(direcao.Normalized() * speed * delta);
}
protected GlobalVariable VariavelGlobal()
{
var globalVariable = (GlobalVariable)GetNode("/root/GlobalVariable");
return globalVariable;
}
protected void ToFire(bool Input, int TempoDeSaida)
{
Area2D Bullet = BulletNode.Instance() as Area2D;
if(Input && ContadorTiro == 0)
{
var Rotation = (GetGlobalMousePosition()- GlobalPosition).Angle();
Bullet.Rotation = Rotation;
Bullet.Position = Position;
GetParent().GetParent().AddChild(Bullet);
ContadorTiro = TempoDeSaida;
}
else if(ContadorTiro > 0)
{
ContadorTiro -= 1;
}
}
}
*I’m talking about BulletNode
*This code is a class that is used by Player and Enemy, however I am instantiating a
generic bulllet
Until recently the code was working but now this happens:
E 0:00:01.623 void Bodyx.ToFire(Boolean , Int32 ):
System.NullReferenceException: Object reference not set to an instance
of an object. <Erro C++> Unhandled exception <Origem C++>
C:\Users\dulou\OneDrive\Documentos\Jogo 001\Body\Bodyx.cs:30 @ void
Bodyx.ToFire(Boolean , Int32 )() Bodyx.cs:30
@ void Bodyx.ToFire(Boolean , Int32 )()
Player.cs:28 @ void Player.Fire()()
Player.cs:52 @ void Player._PhysicsProcess(Single )()