RenderTexture is not been assigned to gameObject material . pls help

using System;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using UnityEngine;
using UnityEngine.UI;

class Kernelss
{
public int firstt = 0;
public int second = 1;

}

public class task_3 : MonoBehaviour
{

[SerializeField] ComputeShader computeShader;
[SerializeField] RenderTexture rt_1;
[SerializeField] RenderTexture rt_demo;
[SerializeField] Material mate_1;
[SerializeField] GameObject go_1;
[SerializeField] GameObject go_2;
[SerializeField] GameObject go_3;

[SerializeField] GameObject go_toWorkWith;
[SerializeField] GameObject go_lastOne;

[SerializeField] Texture2D objectTexture;

Vector2Int resolution = new Vector2Int(512, 512);

Kernelss kernelss;
float normalizedDeltaTime;
float targetTimestep = .02f;

// Start is called before the first frame update
void Start()
{
// Creating and assigning RenderTexture
rt_1 = new RenderTexture(512, 512,0, RenderTextureFormat.ARGB32);
rt_1.enableRandomWrite = true;
rt_1.Create();

rt_demo = new RenderTexture(512, 512,0, RenderTextureFormat.ARGB32);
rt_demo.enableRandomWrite = true;
rt_demo.Create();

if (rt_1 == null || !rt_1.IsCreated())
{
Debug.LogError(“rt_1 is not created.”);
}
if (rt_demo == null || !rt_demo.IsCreated())
{
Debug.LogError(“rt_demo is not created.”);
}

kernelss = new Kernelss();

computeShader.SetVector(“resolution”, new UnityEngine.Vector4(resolution.x, resolution.y));

go_toWorkWith = go_1;
go_toWorkWith.GetComponent().sharedMaterial.SetTexture(“_MainTex”, rt_1);
go_1.GetComponent().sharedMaterial.SetTexture(“_MainTex”, rt_1);

}

// Update is called once per frame
void Update()
{
//timee = Time.deltaTime;
normalizedDeltaTime = Mathf.Clamp(Time.deltaTime, 0.001f, 0.16f); // Clamp to avoid division by zero or very large values
normalizedDeltaTime /= targetTimestep; // Adjust targetTimestep based on your desired simulation speed
computeShader.SetFloat(“_time”, normalizedDeltaTime);

go_lastOne = SelectGameObject();
if(go_toWorkWith != null && go_lastOne != null){
if(go_toWorkWith.name != go_lastOne.name){
go_toWorkWith = go_lastOne;

// // Get the texture from the GameObject
// objectTexture = GetObjectTexture(go_toWorkWith);
// // Set the texture to the RenderTexture
// SetTextureToRenderTexture(objectTexture);

go_toWorkWith.GetComponent().sharedMaterial.SetTexture(“_MainTex”, rt_1);

}
}

if(go_toWorkWith != null){

#region do the compute Shader computation

int kernelHandle = computeShader.FindKernel(“Center”);

// Debug: Check if the kernelHandle is valid
if (kernelHandle < 0)
{
Debug.LogError(“Invalid kernel handle.”);
return;
}

computeShader.SetTexture(kernelHandle, “Result”, rt_1);

// Debug: Verify texture binding
if (rt_1 == null)
{
Debug.LogError(“RenderTexture is null.”);
return;
}

// Ensure the thread group sizes match the shader definition
int threadGroupsX = Mathf.CeilToInt(rt_1.width / 8.0f);
int threadGroupsY = Mathf.CeilToInt(rt_1.height / 8.0f);

// Debug: Log dispatch parameters
Debug.Log($“Dispatching compute shader with thread groups: ({threadGroupsX}, {threadGroupsY}, 1)”);

computeShader.Dispatch(kernelHandle, threadGroupsX, threadGroupsY, 1);

// Debug: Verify dispatch
Debug.Log(“Compute shader dispatched.”);

go_toWorkWith.GetComponent().sharedMaterial.color = Color.red;

Debug.Log(“Performing Graphics.Blit from rt_1 to rt_demo.”);
Graphics.Blit(rt_1, rt_demo);
Debug.Log(“Blit completed.”);

Debug.Log(“Applying rt_demo to go_1.”);
AssignRenderTexture(go_1, rt_demo);
Debug.Log(“Texture applied to go_1.”);

mate_1 = go_toWorkWith.GetComponent().material;
mate_1.SetTexture(“_MainTex”, rt_1);

#endregion

// SetRenderTextureToTexture(rt_1, objectTexture, go_toWorkWith);

// Debug.Log(“—##__” + go_toWorkWith.name);
}

}

void AssignRenderTexture(GameObject go, RenderTexture rt)
{
if (go == null)
{
Debug.LogError(“GameObject is null.”);
return;
}

Renderer renderer = go.GetComponent();
if (renderer == null)
{
Debug.LogError(“Renderer component is missing on the GameObject.”);
return;
}

if (renderer.material == null)
{
Debug.LogError(“Material is missing on the Renderer component.”);
return;
}

if (rt == null || !rt.IsCreated())
{
Debug.LogError(“RenderTexture is null or not created.”);
return;
}

renderer.sharedMaterial.SetTexture(“_MainTex”, rt);
Debug.Log($“RenderTexture assigned to {go.name}”);
}

#region select the gameObject
GameObject SelectGameObject(){
// Check if the left mouse button is pressed
// if (Input.GetMouseButtonDown(0))
// {
// Create a ray from the camera to the mouse position
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;

// Perform the raycast and check if it hits any collider
if (Physics.Raycast(ray, out hit))
{
// Check if the collider’s game object has a specific tag
if (hit.collider.CompareTag(“Selectable”))
{
// Perform actions when a selectable object is hit
// Debug.Log("Selected object: " + hit.collider.gameObject.name);

// You can perform further actions here, such as changing the object’s color or behavior
// hit.collider.gameObject.GetComponent().material.color = Color.red;
return hit.collider.gameObject;
}
}
else{
// Debug.Log(" no gameObject found");
return null;
}

// }
Debug.Log(" no gameObject found");
return null;
}
#endregion

#region get texture and set to render texture to simulate on to it
Texture2D GetObjectTexture(GameObject obj)
{
Renderer renderer = obj.GetComponent();
if (renderer != null && renderer.material != null)
{
Material material = renderer.material;
if (material.mainTexture != null)
{
// Extract the texture from the material
return (Texture2D)material.mainTexture;
}
}
return null;
}

void SetTextureToRenderTexture(Texture2D texture)
{
// Ensure the dimensions of the textures match
if (texture.width != rt_1.width || texture.height != rt_1.height)
{
Debug.LogError(“Texture dimensions do not match render texture dimensions.”);
return;
}

// Convert the source texture to a compatible format
Texture2D convertedTexture = ConvertTextureFormat(texture);

// Set the active RenderTexture
RenderTexture.active = rt_1;

// Copy the texture data into the RenderTexture
Graphics.CopyTexture(convertedTexture, 0, 0, rt_1, 0, 0);

// Clean up
RenderTexture.active = null;
}

Texture2D ConvertTextureFormat(Texture2D texture)
{
// Create a new Texture2D with the same dimensions and RGBA32 format
Texture2D convertedTexture = new Texture2D(texture.width, texture.height, TextureFormat.RGBA32, false);

// Copy the pixels from the source texture to the converted texture
convertedTexture.SetPixels32(texture.GetPixels32());

// Apply changes to the converted texture
convertedTexture.Apply();

return convertedTexture;
}

Texture2D SetRenderTextureToTexture(RenderTexture R_texture, Texture2D texture, GameObject go)
{
if (texture != null && rt_1 != null && go!=null)
{
// Create a new Texture2D with the dimensions of the RenderTexture
texture = new Texture2D(R_texture.width, R_texture.height, TextureFormat.RGBA32, false);
// Read the pixels from the RenderTexture into the Texture2D
texture.ReadPixels(new Rect(0, 0, R_texture.width, R_texture.height), 0, 0);

// Apply the changes to the Texture2D
texture.Apply();

go.GetComponent().material.SetTexture(“_MainTex”, texture);
}

return null;

}
#endregion
}

COMPUTE Shader code

// Each #kernel tells which function to compile; you can have many kernels
#pragma kernel CSMain

// Create a RenderTexture with enableRandomWrite flag and set it
// with cs.SetTexture
RWTexture2D Result;
float2 resolution;
float _time;

float rand(float2 v)
{
return frac(
sin(
dot(v.xy, float2(12.9898 + 0.00001 * + _time, 78.233))
) * 43758.5453

);
}

float2 mid(float2 pos, float scale, float sinval, float cosinval)
{
return pos - scale * float2(sin(sinval), cos(cosinval));
}

float2 mid(float2 pos, float scale, float sinscale, float sinval, float cosscale, float cosinval)
{
return pos - scale * float2(sinscale * sin(sinval), cosscale * cos(cosinval));
}

float peak(float scale, float2 pos)
{
return exp(scale * dot(pos, pos));
}

[numthreads(8,8,1)]
void CSMain (uint3 id : SV_DispatchThreadID)
{
// TODO: insert actual code here!

float2 pos = id.xy / resolution.xy - .5;
float e1 = peak( -11.75, mid(pos, .1, 0.5 + _time, .555555 + _time));
float e2 = peak(-13.23, mid(pos, .1, .75 + 1.3 * _time, -.25 + .2 * _time));
float e3 = peak(-20.121, mid(pos, .253, 3.0, .33 + _time, -2.0, .1 * 2.0 * _time));

Result[id.xy] = float4( e1 + e2 + e3, 0, 0, 1) * 0;
}

RenderTexture is there in inspector, but not assigned on game objects