public partial class Button1 : Button
{
public AudioEffectRecord recordEffect;
public AudioStreamWav recording;
public RichTextLabel text;
Recordnode upnode;
public override void _Ready()
{
upnode = GetNode(“/root/Node2D”);
recordEffect = upnode.recordEffect;
recording = upnode.recording;
text = GetNode(“/root/Node2D/RichTextLabel”);
Pressed += OnPressed;
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
private void OnPressed()
{
text.Text = "[center]recording....[/center] ";
recordEffect.SetRecordingActive(true);
}
}
and other
using Godot;
using System;
public partial class Recordnode : Node2D
{
public int busIndex = AudioServer.GetBusIndex(“Record”);
public AudioEffectRecord recordEffect;
public AudioStreamWav recording;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
recordEffect = (AudioEffectRecord)AudioServer.GetBusEffect(busIndex, 0);
Godot.GD.Print(busIndex);
Godot.GD.Print(recordEffect);
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
}
and send this error
E 0:00:04:036 void Button1.OnPressed(): System.NullReferenceException: Object reference not set to an instance of an object.
<C# 오류> System.NullReferenceException
<C# 소스> Button1.cs:27 @ void Button1.OnPressed()
<스택 추적> Button1.cs:27 @ void Button1.OnPressed()
Callable.generics.cs:39 @ void Godot.Callable.g__Trampoline|1_0(object, Godot.NativeInterop.NativeVariantPtrArgs, Godot.NativeInterop.godot_variant&)
DelegateUtils.cs:86 @ void Godot.DelegateUtils.InvokeWithVariantArgs(nint, System.Void*, Godot.NativeInterop.godot_variant**, int, Godot.NativeInterop.godot_variant*)
Please format your code properly using ``` tags. Indicate the exact script line that’s causing the error and post a screenshot of your scene structure.
public partial class Button1 : Button
{
public Recordnode mainnode;
public AudioEffectRecord recordEffect;
public RichTextLabel text;
public override void _Ready()
{
this.mainnode = GetNode<Recordnode>("/root/Node2D");
this.recordEffect = mainnode.recordEffect;
text = GetNode<RichTextLabel>("/root/Node2D/RichTextLabel");
Pressed += button1pressed;
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
private void button1pressed(){
text.Text = "[center]recording....[/center] ";
this.recordEffect.SetRecordingActive(true);
}
}
and other code
using Godot;
using System;
public partial class Recordnode : Node2D
{
public int recordBusIndex;
public AudioEffectRecord recordEffect;
public Button3 button3;
public Button2 button2;
public Button1 button1;
public RichTextLabel text;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
//button1 = GetNode<Button1>("/root/Node2D/Button1");
//button2 = GetNode<Button2>("/root/Node2D/Button2");
//button3 = GetNode<Button3>("/root/Node2D/Button3");
recordBusIndex = AudioServer.GetBusIndex("Record");
recordEffect = AudioServer.GetBusEffect(
recordBusIndex, 0
) as AudioEffectRecord;
text = GetNode<RichTextLabel>("/root/Node2D/RichTextLabel");
//button1.Pressed += button1pressed;
//button2.Pressed += button2pressed;
//button3.Pressed += button3pressed;
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
}
In any case the error message says exactly which line caused the error. It’s line 27. However you haven’t posted the entire code so we don’t know which of two lines in OnPressed() that is. You also renamed that function in the snipped you posted afterwards.
So look at the error message, identify the line and tell us which exact line that is in the posted snippet.
using Godot;
using System;
public partial class Button1 : Button
{
public Recordnode mainnode;
public AudioEffectRecord recordEffect;
public RichTextLabel text;
public override void _Ready()
{
this.mainnode = GetNode<Recordnode>("/root/Node2D");
this.recordEffect = mainnode.recordEffect; // <---------here code cut
text = GetNode<RichTextLabel>("/root/Node2D/RichTextLabel");
Pressed += button1pressed;
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
private void button1pressed(){
text.Text = "[center]recording....[/center] ";
this.recordEffect.SetRecordingActive(true);
}
}
using Godot;
using System;
public partial class Button1 : Button
{
public Recordnode mainnode;
public AudioEffectRecord recordEffect;
public RichTextLabel text;
public override void _Ready()
{
this.mainnode = GetNode<Recordnode>("/root/Node2D");
text = GetNode<RichTextLabel>("/root/Node2D/RichTextLabel");
Pressed += button1pressed;
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
private void button1pressed(){
text.Text = "[center]recording....[/center] ";
this.recordEffect = mainnode.recordEffect; // <---------here code past
this.recordEffect.SetRecordingActive(true);
}
}
change code like this. do well that. i think _Read() not yet woking in class Recordnode. so this.recordEffect = mainnode.recordEffect call the None. this is call by value. so than not read like call by reference. …. hmm….. i think this is little problem.
Parent’s _Ready() runs only after all of its children’s _Ready()s have been executed.
So if you initialize something in Button1::_Ready() with the value that it initialized in Recordnode::_Ready() that value won’t be there because Recordnode::_Ready() hasn’t run yet.
So, that means the code runs first in the child node, and then in the parent node. Thank you.
I've been experimenting with GoDot again, thinking I'd like to try something new as a hobby after a long time, and I'm starting to grasp the concept again. Thank you.
public override void _Ready()
{
text = GetNode<RichTextLabel>("/root/Node2D/RichTextLabel");
Pressed += button1pressed;
}
public void _afterReady()
{
if (i == false)
{
i = true;
this.mainnode = GetNode<Recordnode>("/root/Node2D");
this.recordEffect = mainnode.recordEffect;
}
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
_afterReady();
}