r/UnityHelp • • Feb 28 '23

I need help to fix the following error :I use Linux (ubuntu) and when I create a project I get this error, how can I solve it?

Post image
4 Upvotes

r/UnityHelp • • Dec 23 '22

gameView.Repaint crash

4 Upvotes

hey guys I can’t open any unity projects without the editor freezing and crashing. Basically I had it working fine with a project for about a month and then it randomly gave me an error saying Failed to present D3D11 swapchain due to device reset/removed, yada yada long error explanation. So I disabled my integrated graphics and kept the dedicated gpu on and the editor would now load and no longer gave that error but now the editor hangs on GameView.Repaint and freezes the whole computer I cant even access task manager to close it. I’m using an old gpu geforce 960m but its been working fine for a month randomly started doing this. I tried upgrading to newest gpu driver it did not help. Tried turning off firewall it did not work. Tried deleting Library folder that did not help. Uninstalled unity and unity hub did a clean install that did not work. Tried downloading newest unity 2022.2 that did not work either. Using unity version 2022.1.23f. Please help me figure this out I cant use unity at all. Not even a blank project will work, if I try to even rotate around the scene view I get SceneView.Repaint waiting for unity to finish code on core module and freezes or whatever and if it loads my main project its gameView.Repaint then freeze. Have to hold the laptop power button to turn it off every time. Any ideas on what to try next would be much appreciated. Oh I also installed unity without the hub that did not work either.


r/UnityHelp • • Dec 09 '22

PROGRAMMING Making A Working Valve

4 Upvotes

Okay, I want to make a working valve in VR. Here are the components it has:

  • A mesh renderer

  • A mesh collider

  • A rigidbody

  • A hinge joint

  • A grabbable script

I want to give it an c# script that:

  1. Tracks the rotation of the valve on the axis it can rotate on,

  2. Runs an if loop with the rotation value as the variable,

  3. Runs an event if the rotation value is within a certain range,

  4. Turns the event off if the rotation value is outside that range.

How do I do that?


r/UnityHelp • • Nov 12 '22

PROGRAMMING How to make an FPS Camera using Netcode for gameobjects and FPS Starter Assets.

4 Upvotes

All I know is that every time a new client joins, all the player set their main camera to that ones.

I use the starter assets but I changed few things to solve this and do the networking:

using Unity.Netcode;
using UnityEngine;
#if ENABLE_INPUT_SYSTEM && STARTER_ASSETS_PACKAGES_CHECKED
using UnityEngine.InputSystem;
#endif

namespace StarterAssets
{
	[RequireComponent(typeof(CharacterController))]
#if ENABLE_INPUT_SYSTEM && STARTER_ASSETS_PACKAGES_CHECKED
	[RequireComponent(typeof(PlayerInput))]
#endif
	public class FirstPersonController : NetworkBehaviour
	{
		[Header("Player")]
		[Tooltip("Move speed of the character in m/s")]
		public float MoveSpeed = 4.0f;
		[Tooltip("Sprint speed of the character in m/s")]
		public float SprintSpeed = 6.0f;
		[Tooltip("Rotation speed of the character")]
		public float RotationSpeed = 1.0f;
		[Tooltip("Acceleration and deceleration")]
		public float SpeedChangeRate = 10.0f;

		[Space(10)]
		[Tooltip("The height the player can jump")]
		public float JumpHeight = 1.2f;
		[Tooltip("The character uses its own gravity value. The engine default is -9.81f")]
		public float Gravity = -15.0f;

		[Space(10)]
		[Tooltip("Time required to pass before being able to jump again. Set to 0f to instantly jump again")]
		public float JumpTimeout = 0.1f;
		[Tooltip("Time required to pass before entering the fall state. Useful for walking down stairs")]
		public float FallTimeout = 0.15f;

		[Header("Player Grounded")]
		[Tooltip("If the character is grounded or not. Not part of the CharacterController built in grounded check")]
		public bool Grounded = true;
		[Tooltip("Useful for rough ground")]
		public float GroundedOffset = -0.14f;
		[Tooltip("The radius of the grounded check. Should match the radius of the CharacterController")]
		public float GroundedRadius = 0.5f;
		[Tooltip("What layers the character uses as ground")]
		public LayerMask GroundLayers;

		[Header("Cinemachine")]
		[Tooltip("The follow target set in the Cinemachine Virtual Camera that the camera will follow")]
		public GameObject CinemachineCameraTarget;
		[Tooltip("How far in degrees can you move the camera up")]
		public float TopClamp = 90.0f;
		[Tooltip("How far in degrees can you move the camera down")]
		public float BottomClamp = -90.0f;

		// cinemachine
		private float _cinemachineTargetPitch;

		// player
		private float _speed;
		private float _rotationVelocity;
		private float _verticalVelocity;
		private float _terminalVelocity = 53.0f;

		// timeout deltatime
		private float _jumpTimeoutDelta;
		private float _fallTimeoutDelta;

	
#if ENABLE_INPUT_SYSTEM && STARTER_ASSETS_PACKAGES_CHECKED
		private PlayerInput _playerInput;
#endif
		private CharacterController _controller;
		private StarterAssetsInputs _input;
		[SerializeField] private GameObject _mainCamera;

		private const float _threshold = 0.01f;

		private bool IsCurrentDeviceMouse
		{
			get
			{
				#if ENABLE_INPUT_SYSTEM && STARTER_ASSETS_PACKAGES_CHECKED
				return _playerInput.currentControlScheme == "KeyboardMouse";
				#else
				return false;
				#endif
			}
		}
		
		public override void OnNetworkSpawn()
		{
			// get a reference to our main camera
			if (_mainCamera == null)
			{
				foreach (Transform child in gameObject.transform)
				{

					if (child.name == "PlayerCameraRoot")
					{
						foreach (Transform granchild in child.transform)
						{
							if (granchild.tag == "MainCamera")
								_mainCamera = granchild.gameObject;
						}
					}
				}
			}

		}

		private void Start()
		{

			if(!IsOwner) return;
			_controller = GetComponent<CharacterController>();
			_input = GetComponent<StarterAssetsInputs>();
#if ENABLE_INPUT_SYSTEM && STARTER_ASSETS_PACKAGES_CHECKED
			_playerInput = GetComponent<PlayerInput>();
#else
			Debug.LogError( "Starter Assets package is missing dependencies. Please use Tools/Starter Assets/Reinstall Dependencies to fix it");
#endif

			// reset our timeouts on start
			_jumpTimeoutDelta = JumpTimeout;
			_fallTimeoutDelta = FallTimeout;
			Cursor.visible = false;
		}

		private void Update()
		{
			if(!IsOwner) return;
			JumpAndGravity();
			GroundedCheck();
			Move();

		}

		private void LateUpdate()
		{

			CameraRotation();

		}

		private void GroundedCheck()
		{
			// set sphere position, with offset
			Vector3 spherePosition = new Vector3(transform.position.x, transform.position.y - GroundedOffset, transform.position.z);
			Grounded = Physics.CheckSphere(spherePosition, GroundedRadius, GroundLayers, QueryTriggerInteraction.Ignore);
		}

		private void CameraRotation()
		{
			// if there is an input
			if (_input.look.sqrMagnitude >= _threshold)
			{
				//Don't multiply mouse input by Time.deltaTime
				float deltaTimeMultiplier = IsCurrentDeviceMouse ? 1.0f : Time.deltaTime;
				
				_cinemachineTargetPitch += _input.look.y * RotationSpeed * deltaTimeMultiplier;
				_rotationVelocity = _input.look.x * RotationSpeed * deltaTimeMultiplier;

				// clamp our pitch rotation
				_cinemachineTargetPitch = ClampAngle(_cinemachineTargetPitch, BottomClamp, TopClamp);

				// Update Cinemachine camera target pitch
				CinemachineCameraTarget.transform.localRotation = Quaternion.Euler(_cinemachineTargetPitch, 0.0f, 0.0f);

				// rotate the player left and right
				transform.Rotate(Vector3.up * _rotationVelocity);
			}
		}

		private void Move()
		{
			// set target speed based on move speed, sprint speed and if sprint is pressed
			float targetSpeed = _input.sprint ? SprintSpeed : MoveSpeed;

			// a simplistic acceleration and deceleration designed to be easy to remove, replace, or iterate upon

			// note: Vector2's == operator uses approximation so is not floating point error prone, and is cheaper than magnitude
			// if there is no input, set the target speed to 0
			if (_input.move == Vector2.zero) targetSpeed = 0.0f;

			// a reference to the players current horizontal velocity
			float currentHorizontalSpeed = new Vector3(_controller.velocity.x, 0.0f, _controller.velocity.z).magnitude;

			float speedOffset = 0.1f;
			float inputMagnitude = _input.analogMovement ? _input.move.magnitude : 1f;

			// accelerate or decelerate to target speed
			if (currentHorizontalSpeed < targetSpeed - speedOffset || currentHorizontalSpeed > targetSpeed + speedOffset)
			{
				// creates curved result rather than a linear one giving a more organic speed change
				// note T in Lerp is clamped, so we don't need to clamp our speed
				_speed = Mathf.Lerp(currentHorizontalSpeed, targetSpeed * inputMagnitude, Time.deltaTime * SpeedChangeRate);

				// round speed to 3 decimal places
				_speed = Mathf.Round(_speed * 1000f) / 1000f;
			}
			else
			{
				_speed = targetSpeed;
			}

			// normalise input direction
			Vector3 inputDirection = new Vector3(_input.move.x, 0.0f, _input.move.y).normalized;

			// note: Vector2's != operator uses approximation so is not floating point error prone, and is cheaper than magnitude
			// if there is a move input rotate player when the player is moving
			if (_input.move != Vector2.zero)
			{
				// move
				inputDirection = transform.right * _input.move.x + transform.forward * _input.move.y;
			}

			// move the player
			_controller.Move(inputDirection.normalized * (_speed * Time.deltaTime) + new Vector3(0.0f, _verticalVelocity, 0.0f) * Time.deltaTime);
		}

		private void JumpAndGravity()
		{
			if (Grounded)
			{
				// reset the fall timeout timer
				_fallTimeoutDelta = FallTimeout;

				// stop our velocity dropping infinitely when grounded
				if (_verticalVelocity < 0.0f)
				{
					_verticalVelocity = -2f;
				}

				// Jump
				if (_input.jump && _jumpTimeoutDelta <= 0.0f)
				{
					// the square root of H * -2 * G = how much velocity needed to reach desired height
					_verticalVelocity = Mathf.Sqrt(JumpHeight * -2f * Gravity);
				}

				// jump timeout
				if (_jumpTimeoutDelta >= 0.0f)
				{
					_jumpTimeoutDelta -= Time.deltaTime;
				}
			}
			else
			{
				// reset the jump timeout timer
				_jumpTimeoutDelta = JumpTimeout;

				// fall timeout
				if (_fallTimeoutDelta >= 0.0f)
				{
					_fallTimeoutDelta -= Time.deltaTime;
				}

				// if we are not grounded, do not jump
				_input.jump = false;
			}

			// apply gravity over time if under terminal (multiply by delta time twice to linearly speed up over time)
			if (_verticalVelocity < _terminalVelocity)
			{
				_verticalVelocity += Gravity * Time.deltaTime;
			}
		}

		private static float ClampAngle(float lfAngle, float lfMin, float lfMax)
		{
			if (lfAngle < -360f) lfAngle += 360f;
			if (lfAngle > 360f) lfAngle -= 360f;
			return Mathf.Clamp(lfAngle, lfMin, lfMax);
		}

		private void OnDrawGizmosSelected()
		{
			Color transparentGreen = new Color(0.0f, 1.0f, 0.0f, 0.35f);
			Color transparentRed = new Color(1.0f, 0.0f, 0.0f, 0.35f);

			if (Grounded) Gizmos.color = transparentGreen;
			else Gizmos.color = transparentRed;

			// when selected, draw a gizmo in the position of, and matching radius of, the grounded collider
			Gizmos.DrawSphere(new Vector3(transform.position.x, transform.position.y - GroundedOffset, transform.position.z), GroundedRadius);
		}
	}
}

And this is my Prefab for the player:

My Network Manager:

Note: I don't know if it matters. It probably does not but I am raycasting with the cameras.

Prize: I will upvote 10 of your posts on your profile. If you post before tomorrow, I'll double it. This is just for encouragment becouse I know multiplayer is pain in the ass and people don't have to help an stranger in such an hard task. But I will do it.


r/UnityHelp • • Jul 28 '22

UNITY Hello! its me again. How could I make it so that if my character flies in from one side of the screen, it keeps its momentom and comes out from the other? rough image below:

4 Upvotes

r/UnityHelp • • Jun 30 '22

What is the best way to create area triggers?

4 Upvotes

I'm creating a game where I would need a trigger that when a player walks through it it can change a variable. The closest I've gotten is "void OnTriggerEnter(Collider other)", the only issue with this is that it's too global and I need it to trigger individually without attaching a separate script to different objects. Is there anyway to either set an individual GameObject to the method so that it only triggers on predetermined GameObjects separately or is there just a better way to do this in general? Hopefully this makes sense.


r/UnityHelp • • Mar 23 '22

PROGRAMMING Where can I find a first person controller script?

4 Upvotes

I find it really hard to make a first person controller script that works, can I just download one?


r/UnityHelp • • Mar 14 '22

UNITY Need help understanding "Dirty canvases"

4 Upvotes

Hello everyone!

I'm having trouble understanding the concept of dirty canvases, and I hope you can help.

As I understand it, if I have a canvas with an image and text element under it, and the text changes; the whole canvas needs to be redrawn. This happens because the entire canvas is marked "dirty" and so it has to be redrawn.

So far so good.

Now consider the following example:

I have a parent canvas A.

Inside it, I have child canvas B and child canvas C.

B holds the image, and C holds the text.

If the text changes, it makes sense that C is redrawn. Now, since something changed under A, does that mean that A is redrawn, and therefore B is redrawn as well?

I'm currently facing an issue of this nature at work so any help will be appreciated.

Thanks!


r/UnityHelp • • Feb 22 '22

PROGRAMMING MIDI Output

4 Upvotes

I'm looking to have MIDI output for my project but not having any luck searching for information. Lots of information about MIDI input. Anyone able to point me in the right direction or anything?


r/UnityHelp • • Feb 07 '22

UNITY Exported blender model shader directions are off.

4 Upvotes

https://imgur.com/a/R0FuzOL My shader should be rendering the yellow glow from the bottom up, like it does with the default cube. I am trying it on a blender model I imported but seems to be having issues despite the model being in the proper upright position and rotations are all 0. Anyone know the proper settings I need to export this properly?

Edit

Another Example of the shader being used by default unity 3d objects. https://imgur.com/a/ma5GchV

Shader tutorial :https://www.youtube.com/watch?v=1GPvI-5bOSk&t=660s Video tutorial I followed for the shader.


r/UnityHelp • • Dec 11 '21

UNITY Error using Unity while Build and Run of Android Application

4 Upvotes

Hi, I am just starting out with Unity. I am trying to run an android app using Build and Run. This is the error I am facing.

Resource 'style/Theme.AppCompat.NoActionBar' not found in AndroidManifest.xml:25.

I tried these solutions but had some problems:

  1. android - Unity says resource style/Theme.AppCompat.Light.NoActionBar not found - Stack Overflow

I dont know where to download these .aar files

2) Upgrading firebase 6.0.0 and google GPGS cause error in AndroidSupportLibraryResolver · Issue #235 · facebook/facebook-sdk-for-unity · GitHub

I have the latest version of External Dependency Manager Installed.

Please help me out. I am a beginner in Unity.


r/UnityHelp • • Dec 07 '21

PROGRAMMING Picking Up Objects

4 Upvotes

Okay, I am making a 3D physics 3rd person game. I want to make it so that when C is pressed, my player character picks up any object within a hitbox, and carries it around until C is pressed again, causing her to throw it. Here's the code that I'm using for the rest of her movement:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerMovement : MonoBehaviour
{
    CharacterController character;
    Collider stomp;
    Collider punch;
    
    float moveX;
    float moveZ;
    float moveY;

    Vector3 movement;
    private Vector3 rotation;
    Vector3 velocity;

    public float speed;
    public float gravity;
    public float rotationSpeed = 180;
    public float crouchSpeed = 8;
    public float jump = 10f;
    bool isGrounded;
    public Transform groundCheck;
    public LayerMask groundMask;
    public float groundDistance = 0.2f;
    public float highJump = 25f;
    public float sprintSpeed = 25f;
    public float distance = 3f;
    public float mass = 45f;
    //public float stompPower = 1f;

    void Start()
    {
       character = GetComponent<CharacterController>();
       stomp = GetComponentInChildren<Collider>();
       punch = GetComponentInChildren<Collider>();
    }

    void Update()
    {
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
       if (isGrounded && velocity.y < 0) {
          velocity.y = -2f;
        }
       this.rotation = new Vector3(0, Input.GetAxisRaw("Horizontal") * rotationSpeed * Time.deltaTime, 0);
       Vector3 move = new Vector3(0, 0, Input.GetAxisRaw("Vertical") * Time.deltaTime);
       move = this.transform.TransformDirection(move);
       this.transform.Rotate(this.rotation);
       character.Move(move * speed);
       if (Input.GetKey(KeyCode.Z) && isGrounded)
        {
          character.height = .75f;
          character.Move(move * crouchSpeed);
          //stomp.enabled = false;
          if (Input.GetButtonDown("Jump") && isGrounded)
           {
             velocity.y = Mathf.Sqrt(highJump * -2f * gravity);
           }
        }
       //else if (Input.GetKey(KeyCode.Z))
        //{
          //stomp.enabled = true;
        //}
       else
        {
          character.height = 1.5f;
          character.Move(move * speed);
          //stomp.enabled = false;
          if (Input.GetButtonDown("Jump") && isGrounded)
           {
             velocity.y = Mathf.Sqrt(jump * -2f * gravity);
           }
        }
       character.Move(movement * speed*Time.deltaTime);
       velocity.y += gravity * Time.deltaTime;
       character.Move(velocity * Time.deltaTime);
       if (Input.GetKey(KeyCode.LeftShift))
        {
            character.Move(move * sprintSpeed);
        }
        else if (Input.GetKeyDown(KeyCode.Z) && Input.GetKeyDown(KeyCode.LeftShift))
        {
            velocity.z = Mathf.Sqrt(-2f* gravity* distance);
        }
        else
        {
            character.Move(move * speed);
        }
    }
    //private void OnTriggerEnter(Collider other)
    //{
    //var hit = other.GetComponent<Damagable>();
    //if (hit != null)
    //{
    //hit.damage(stompPower);
    //}
    //}
    private void OnControllerColliderHit(ControllerColliderHit hit)
    {
        Rigidbody rb = hit.collider.attachedRigidbody;
        if (rb != null && !rb.isKinematic)
        {
            rb.velocity = hit.moveDirection * mass;
        }
    }
}

Okay, what do I add?


r/UnityHelp • • Nov 16 '21

UNITY Confusion Around Canvas Element in Unity 2D Project

4 Upvotes

EDIT: I think we worked it out, wasn't sure how to make the image clearer so I ghosted, that was wrong of me and I apologise. But thanks for the responses anyway.

I'm working on a SeaJam game with my Dad as the head programmer but he isn't used to Unity and I don't know enough to help out either.

It may sound like a silly question but he added an image to a canvas element and now whenever he clicks the image a strange wire graphic appears on the side of the scene window showing an upside down mirror of the canvas and image. (Link to screenshot: https://imgur.com/PzTEqdm)

He's finding it really annoying and isn't sure a) what it is, and b) how to get rid of it. Any help is appreciated!


r/UnityHelp • • Nov 05 '21

PROGRAMMING How do I code an attack with a hitbox that can make certain environmental objects break?

Thumbnail
gallery
4 Upvotes

r/UnityHelp • • Oct 28 '21

How do I make my character jump?

4 Upvotes

I am using a character controller and SimpleMove so it automatically moves and takes gravity into account, but nothing I do makes it jump upwards. I realize I could switch to Move but I have had mixed results and SimpleMove perfectly does what I want besides jumping. I just need a way to lift off.

Vector3 vel=new Vector3(0.0f, 5.0f, 0.0f);

if (rb.isGrounded)

{

if (rb.velocity.y < -30) //falldamage

{

gameObject.GetComponent<takedamage>().fallhurt(rb.velocity.y);

}

i = 0; //reset jump

}

if (Input.GetKeyDown(KeyCode.Space) && (i < 2))

{

jump();

}

private void jump()

{

rb.Move(vel+(movvec*Time.deltaTime));

i++;

}


r/UnityHelp • • Sep 25 '21

Easier way to Print Class:Method name in Debug.Log

4 Upvotes

In C/C++, whenever I print a debug statement, I always prepend my text with function/line no. for instance

printf( "%s:%d: error message\n", __FUNCTION__, __LINE__ );

Now, I've found a way to do something similar in Unity/C#and that is

string func =  System.Reflection.MethodBase.GetCurrentMethod().DeclaringType + ":" + System.Reflection.MethodBase.GetCurrentMethod().Name;

Debug.Log( func + " error message" );

My question is, is there an easier way to do this rather than declare "string func = " at the beginning of each function? I've tried looking into user #define in Unity, but as far as I can tell (and I could be wrong), it doesn't really let you define a body for your definition

so Unity allows you to do this;

#define TAG

but not

#define TAG insert custom C# code here;

for instance, can I even do something like this?

#define PRINT_HERE  Debug.Log( "Over Here" );

Also, I apologize for bombarding this site with back-to-back questions. Thanks in advance for your help.


r/UnityHelp • • Aug 29 '21

PROGRAMMING How do I get a component's property as method parameter?

4 Upvotes

So I'm trying to change the Light component's Range property but I'm not sure what to put as its type. I tried to get it as string and then convert that to the Range property but I couldn't figure out how. Does anyone know how to do this?


r/UnityHelp • • Aug 27 '21

UNITY Camera Issues

4 Upvotes

r/UnityHelp • • Aug 15 '21

UNITY Help with making my first game

4 Upvotes

Hello, I want to start working on a Slender clone as my first project. But I have no idea what I'm doing, I'm mostly going by tutorials because I have no real knowledge with C#, however finding good quality tutorials are hard especially with what I plan to do.

I want help, but I also don't want a "Copy and paste a mountain of code and figure it out from there" kind of help. I would like to write it out and actually understand and learn what I'm writing.

Some help with making a simple flashlight, menus, and "Slender-like" AI, would be nice. Thank you in advance for you're help. Also I'm sorry if I'm asking for a bit too much, it's my first time asking for help like this


r/UnityHelp • • Aug 09 '21

How do I fix unity 2d tilemap glitches?

4 Upvotes

r/UnityHelp • • Aug 03 '21

Unity not showing vertex paint from blender

4 Upvotes

I made a island for a vr game im working on and i created it in blender and it has color and in unity it didnt. So i kept putting different shaders on materials and a few had the vertex paint on but washed out and not the same color. So im wondering how I fix this to look normal.


r/UnityHelp • • Jul 17 '21

OTHER Hi ! I don't know why this keeps happening and my artwork isn't rendering in game. can someone help me ? any help will be appreciated. Thanks.

4 Upvotes

r/UnityHelp • • Jun 12 '21

needed help please

4 Upvotes

[HELP]

hai, im trying to upload my avatar for vrchat and i watched a video and it said click VRChatSDK and there will be options right for me only option there is Utilities,so how can i fix this or did i do something wrong?


r/UnityHelp • • May 28 '21

Code for picking up object wont work.

4 Upvotes

I am new to c# so sorry if its obvious, but I have it so if you walk over a headlamp it will be teleported onto your head. by having a trigger on the helmet and the destination a child to the player. but nothing happens when you do that. Heres the code:

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class Teleporting : MonoBehaviour {

public Transform teleportTarget;

public GameObject theHelmet;

public GameObject thePlayer;

void OnTriggerEnter(Collider thePlayer)

{

theHelmet.transform.position = thePlayer.transform.position;

}

}