#💻┃code-beginner

1 messages · Page 661 of 1

wintry quarry
#

or any other code in this file?

#

Can you share the full script?

regal magnet
#

oh wait i have other components

#

just 1 script

regal magnet
wintry quarry
#

use !code

eternal falconBOT
regal magnet
wintry quarry
regal magnet
wintry quarry
#

I don't see any problems

#

maybe it's your keyboard>

keen cargo
#

maybe debug the horizontalinput?

#

see if the value is dropping down

wintry quarry
#

Yeah good next step

#

Debug.Log($"Horizontal input is {horizontalinput}");

#

And make sure Collapse is turned off in the console

regal magnet
#

i did

#

even after stop its still send -1

#

btw this bug is not only for "d"

wintry quarry
regal magnet
#

i also get stuck with "a" as well

#

no only keyboard

wintry quarry
#

do you have any other keyboards you can try?

regal magnet
#

no but i think its not about keyboard

wintry quarry
#

also double check all your USB ports etc for devices

#

and disable bluetooth

regal magnet
#

because i was using this code before its was working

#

i dont know what i change but its not working now

wintry quarry
#

You can also try restarting Unity and/or your PC

regal magnet
#

lets try

keen cargo
#

does this stopping happen anywhere else in the scene? like for an example if you place your character somewhere else and move them there

#

could be a nasty little collider

regal magnet
#

i restart my pc still the same and its happen in everywhere

#

but this thing also broke my dash

#

i still can dash but not going anywhere

compact sundial
#

can someone ACTUALLY help me instead of directing me to a video? ik its basic stuff but I have trouble with basic stuff sometimes and for some reason, the more complicated stuff makes more sense to me

regal magnet
#

i will try to upload short video to yt

wintry quarry
compact sundial
#

I removed everything that deals with jumps so I can start over on that front

using UnityEngine;
using UnityEngine.InputSystem;

[RequireComponent(typeof(CharacterController))]
public class PlayerController : MonoBehaviour
{
    private float speed = 0f;
    private float TurnSpeed = 100f;
    private float xRotation = 0f;
    private float yRotation = 0f;
    public float SensitivityX = 10f;
    public float SensitivityY = 10f;
    private Vector3 PlayerVelocityVar = Vector2.zero;
    private Vector2 MoveInput = Vector2.zero;
    private CharacterController playerController;
    [SerializeField] private float playerSpeed = 2.8f;
    private float jumpHeight = 1.0f;
    private float gravityValue = -9.81f;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        playerController = GetComponent<CharacterController>();
    }

    // Update is called once per frame
    void Update()
    {
        PlayerVelocityVar = new Vector3(MoveInput.x, 0, MoveInput.y);
        playerController.Move(PlayerVelocityVar * playerSpeed * Time.deltaTime);

        float mouseX = Input.GetAxis("Mouse X");
        float mouseY = Input.GetAxis("Mouse Y");

        xRotation += mouseX * SensitivityX;
        yRotation -= mouseY * SensitivityY;
        transform.localEulerAngles = new Vector3(yRotation, xRotation, 0f);

        float rotateX = mouseX * SensitivityX;
        float rotateY = mouseY * SensitivityY;

        transform.Rotate(rotateX, rotateY, 0f);

    }

    public void OnFire(InputAction.CallbackContext context)
    {
    }

    public void OnMove(InputAction.CallbackContext context)
    {
        MoveInput = context.ReadValue<Vector2>();
    }
}
wintry quarry
regal magnet
wintry quarry
regal magnet
#

no

compact sundial
keen cargo
#

we can't help you better than the tutorials i sent you to

#

they explain as plainly as you possibly can

compact sundial
#

the tutorial is too slow for me

regal magnet
compact sundial
#

its just not clicking

keen cargo
#

are you trying to speedrun learning? this isn't what you said before about "not understanding beginner concepts"

compact sundial
keen cargo
#

btw you can speed up the video if it's too slow

wintry quarry
keen cargo
#

what's not clicking for you exactly?

compact sundial
#

idk, its just not how I learn

keen cargo
#

so how do you learn?

wintry quarry
regal magnet
#

yes

wintry quarry
#

Can you show the inspector for your tilemap? I'd like to see all the components on it, especially the TilemapCollider and CompositeCollider if you have them

compact sundial
#

well its easier if I can ask questions, and/or someone teaches it to me personally. I learn by doing and step by step and videos just dont help

#

well rarely they do

wintry quarry
#

well you can ask specific questions here (ideally in a thread), but don't expect anyone to be your personal tutor for free

naive pawn
compact sundial
#

well I was just hoping that someone could help me when I need it

wintry quarry
#

You need to

regal magnet
#

what is that

naive pawn
compact sundial
wintry quarry
# regal magnet what is that

Do this:
On your tilemapcollider2d set "Composite Operation" to "Merge".

Then add a CompositeCollider2D component to the same GameObject and set Geometry Type to "Polygons"

naive pawn
wintry quarry
# regal magnet what is that

The composite collider merges all the physics shapes in the tilemap into a single collider so you don't get stuck on the edges between each tile.

naive pawn
#

also, there are existing resources that aren't videos

#

there are plenty of text guides that are step-by-step

regal magnet
compact sundial
keen cargo
#

ok there are very detailed text guides, a lot of them are actually

#

where are you getting these vague guides from

naive pawn
#

tutorial quality does vary, if one isn't working out for you just use a different one

#

have you checked out unity !learn

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

keen cargo
#

i pointed him there earlier

compact sundial
#

🤷

#

why does the junior programmer course take 7 hours?

keen cargo
#

because it counts the video lengths + estimates how much time you take on doing the exercises

#

it's usually an over estimate

rocky canyon
#

on "average" it takes 7

median hatch
rocky canyon
#

most of em are over-estimated in my opinion but ya, theres no real answer here

median hatch
#

if you can't bother to sit down and learn the basics

#

then don't bother at all

#

this goes for anything

compact sundial
#

in that case I might as well kill myself

frigid sequoia
#

Pffff, well, if you can't stand 7 hours of sitting down and trying to understand stuff, you have like no future on any game engine

#

Sadly that's how it goes

keen cargo
#

there's 2 ways this can go for you

  • you do the unity learn stuff or another tutorial, you figure out what's wrong, life good
  • you ask someone to give you the answer, you don't know what is wrong, life bad
inland temple
#

Is there any wa to make a sharpnen effec

eternal needle
# compact sundial why does the junior programmer course take 7 hours?

Stuff like university takes years teaching you to be a beginner in the real world. If you have no clue about programming or how to make a game, what did you expect? It's not like you need to spend 7 hours today doing that one course. That one course still won't even prepare you to make a game. You'll just have a slightly better understanding of what the engine can do.

keen cargo
compact sundial
#

thats really sad because I have learned things in a week that take most people a year

eternal needle
keen cargo
#

you learn some things faster than others

it doesn't mean that you'll learn this fast

#

it took me like, until i was 23 to properly tie my shoelaces

final forge
#

What is the "recommended" way to manage enemies dying in a game? I was thinking 1) global list of enemies, every update it checks the list, or 2) an event based system, the global list subscribes to the enemy's death event. does anyone have tips? I don't have a practical use case, I just want to know for later

frigid sequoia
eternal needle
compact sundial
#

well seems like you people cant help me so im leaving

keen cargo
#

we are trying to help you, we can't help someone who won't help themselves

median hatch
keen cargo
#

oop he's gone

frigid sequoia
keen cargo
alpine summit
#

he learned how to leave the server in 5 minutes when most people take years cluelesS

eternal needle
# median hatch you're too smart for us what can i say

these kind of comments really are pointless. theres no point trolling someone who was looking for advice. i was trying to offer them a realistic perspective on things and being aggressive to someone like this is just useless

median hatch
final forge
eternal needle
frigid sequoia
final forge
#

oh ya the update one would always be polling so that would b bad if they're mostly alive anyways

median hatch
eternal needle
median hatch
#

no problems so far

runic lance
#

he's probably just a high school guy (or not even that old) that didn't have any real challenges yet
he'll learn to learn at some point, hopefully

eternal needle
#

yep. but people basically teasing them and being aggressive sure doesnt help

frigid sequoia
#

It depends on how everything is setup in your game, but if everything is on a list, and they are just dissabled (cause you are pooling them) you can just have them referencing the list as a manager to do something when they die instead of having events

#

Cause even if they are very usefull sometimes, you lose track of where the code is going throught if you start adding a lot of events

eternal needle
frigid sequoia
keen cargo
keen cargo
#

though should probably end this topic, it'll clog up the channel

eternal needle
final forge
#

Are they cleaner because the enemies class doesn't need to know about the list singleton class

#

Is the events solution cleaner* i mean

frigid sequoia
#

The thing is, yes, call stuff for events looks more "clean" but then, if everything gets more complex, tracking what is calling what gets harder and harder

#

But in this case sounds like no issue

eternal needle
# final forge Are they cleaner because the enemies class doesn't need to know about the list s...

yes and plus you might end up having other things subscribe to a characters death so it makes sense to have anyways. Random example but if you want certain enemies to explode on death, you might have a component attached to them to do this. In the class on the enemy, you wouldnt want to start adding logic like
if(explodeAfterDeath != null) ...
because you'd be modifying the class for every feature in the future. this goes against open/close principle in SOLID. it'd be easier if the component subscribed to the death

frigid sequoia
#

Tbh, if you have a exploding enemy, you probably want a whole different logic and script rather than just adding an OnDeath do X listener

frigid sequoia
#

I don't think any of the exploding enemies I have seen in games have anything in common with the normal ones other than the very basic components that make an enemy like health, pathfidning and stuff

eternal needle
#

If the only difference between 2 characters is one explodes, and you need to rewrite their entire npc class, you're doing it wrong.

ashen arch
frigid sequoia
#

They probably do different things like try to track down the player, stop briefly before reaching them, maybe tick before exploding.... that kind of stuff

eternal needle
#

I really dont see a need to continue this if your argument is going to be that my completely random example isnt going to be the best game design.

frigid sequoia
#

My argument is... that creating new enemies by raw adding just do X when Y is not a great workflow??

eternal needle
#

The example was straightforward. An enemy that explodes on death.
You're talking about something completely different

lean pelican
#

How can I stop a child (that just contains a Sprite Renderer) from rotating along with its Parent?

#

There's this component called Rotation Constraints, but even after looking at the API I have no idea what it does/how it works.

brave robin
#

Rotation Constraint is similar, but makes it rotate with the source. Like if you want a compass arrow to point where the player is facing, but not move with the player.

ashen arch
# lean pelican How can I stop a child (that just contains a Sprite Renderer) from rotating alon...

You could add a script to the child object to reference the parent and counter-rotate it. ```cs
using UnityEngine;

public class MaintainWorldRotation : MonoBehaviour
{
Quaternion initialWorldRotation;
Transform parentTransform;

void Start()
{
    initialWorldRotation = transform.rotation;
    parentTransform = transform.parent;
}

void LateUpdate()
{
    if (parentTransform != null)
    {
        Quaternion inverseParentRotation = Quaternion.Inverse(parentTransform.rotation);
        transform.rotation = initialWorldRotation * inverseParentRotation;
    }
}

}

brave robin
#

What Position Constraint and Rotation Constraint are especially good for is objects that conceptually don't make sense to be children of what is moving them. Like if you can pick up an object, wave it around, and then just as easily drop it, it's easier to do all of that with constraints. Just set the constraint source and enable it when its picked up, and null the source and disable when dropped.
I have a camera that follows the player from above, but when in map view it can freely scroll over the map in any direction, so it made more sense to constrain when acting as a minimap, and then unconstrain when scrolling over the map.

#

Also when the player goes up and down floors I didn't want it smoothly going up and down with the player. I needed it to snap to the floor the player was on, so that the transition was clean on the map view. So I would disable the Y on the constraint and manually control it.

timber tide
#

Rotation constraint should really just be a boolean on the transform component

#

instead it has to be convoluted with some blending properties which no one uses anyway

brave robin
frigid sequoia
#

Is there a better way to show that on the editor itself rather than in console??

#

Like a boolean I cannot interact with?

lean pelican
ashen arch
rich adder
frigid sequoia
frigid sequoia
rich adder
#

some like this prob

#

use a ternary to print specific label based on isValid or not, you can even color it green vs red or something

eternal needle
#

custom inspector here is definitely the way rather than a separate component. you'd probably want to DrawDefaultInspector and then add a label afterwards with the info you want

brave robin
frigid sequoia
#

Ye, I figured it out

final forge
#

Is it bad to use a lot of interfaces? For example, if I have a projectile, I might make it implement an interface indicating its a pooled object, as well as a projectile interface, or if it's a monster, I'll have it have a health interface, interface to handle its death, etc

wintry quarry
final forge
#

When you say another component, do you mean like a Monobehavior script?

final forge
wintry quarry
#

yes

#

and then you don't have to reimplement the basics of subtracting hp, taking damage, checking for death, etc. over and over

#

as for having different behavior on different things with health - you could have the health script expose C# or UnityEvents like OnDeath and/or OnHealthChanged

#

that way the basics would be the same everywhere but you can have a lizard whose tail falls off when his health reaches 5

#

or whatever

final forge
#

Ok thanks, I'll try this

#

yes

strong wren
#

But if you do end up with multiple components with health, interface is a good way to expose it.

final trellis
#

bro r u high

#

unity docs says the == with Vector3s works on an approximate

wintry quarry
#

try _moveDir.magnitude < 0.01

final trellis
#

that seems to work, odd, since _moveDir is from input

teal viper
#

The approximation is something like 0.000001 or less. It's supposed to be epsilon - the smallest value a float can have afaik.

final trellis
#

thank you floating points very cool

teal viper
#

It's meant to avoid floating point error. Anything above that would not be equal

frigid sequoia
#

On SceneLoaded would happen after of before the awakes on the scene?

frigid sequoia
#

Cool then, my thing should work I think lol

hidden fossil
#

do i have to worry about this: NullReferenceException: Object reference not set to an instance of an object
Bullet.OnCollisionEnter2D (UnityEngine.Collision2D other) (at Assets/Code/Scripts/Bullet.cs:33)

#

line 33: private void OnCollisionEnter2D(Collision2D other) {
other.gameObject.GetComponent<Health>().TakeDamage(bulletDamage);
Destroy(gameObject);
}

#

its not affecting the game but its sending a lot of error messages

teal viper
jaunty bay
#

sometimes when i code the prototype, i do it very unorganized for the sake of just getting it done because im very unexperienced to have the intuition on what should be put where. is it fine or do i need to maintain the habit of organizing the code first?

eternal needle
#

It depends on what you're coding too. If the foundation of your game is lazily made then well everything is built on a bad foundation. If some obscure 1 time interaction is coded poorly then it's not a big deal

charred spoke
#

If you plan on extending your prototype to a full game then you should take the time and effort to keep it organised and clean. However this in a way going against the idea of a prototype, at least for me

#

I at least code my prototypes fast and dirty and if they work out, then I take the time to completely refactor everything into a foundation that will work for production

grand mango
#

if anyone could help me out here, im trying to make a small system for a game im doing, and im trying out the UI toolkit for editor panels.
im trying to make a tag system for a game im working on, and im having trouble with the 'testing#' buttons either wrapping properly or the area they are inside of expanding down as i add them

Originally it was just the 2 visual elements at root and while it would wrap, it wouldnt expand downward, and then i made it a child and attempted to do the same, (code is hooked up to properly create buttons in the right visual element) and it wont wrap now.

unity vers - version 6000.0.31f1

timber tide
novel steeple
#

This is probably a really easy fix, but I can’t figure out why my camera is so zoomed in on game but on scene it is normal? It also goes over to the side when I try to use a camera follow script and I don’t think the scripts the problem.

keen dew
shut swallow
#

quick question: if i need to delay a function (in this case, delaying the gravity to be instantly applied on the player after an air dash), would it be better if i use invoke or a coroutine?

runic lance
#

Invoke is simpler to use, but it's much less flexible and gives you less control

wintry quarry
shut swallow
#

is one more efficient than the other (in terms of processing) in this scenario

north kiln
#

Efficiency should not be a consideration at this scale

shut swallow
#

right

runic lance
#

for some reason the docs say that Coroutines provide better performance, although without many details

wintry quarry
#

Because they don't need to resolve a string to a method

#

They don't need to do reflection or anything

runic lance
#

sincerely I never seen anyone use Invoke in a serious project anyway

sour fulcrum
#

I am genuinely curious where people find out about Invoke, is it from c# related tutorials?

wintry quarry
#

Probably tutorials yes

sour fulcrum
#

I never was introduced to it when learning c# in unity, I've only seen it from other beginners

wintry quarry
#

It's not a c# thing

#

It's a Unity thing

#

You can be sure anything beginners are doing came from a tutorial or AI

naive pawn
#

or unfortunately trial-and-error

#

(in the case of code with no errors, warnings, or colors)

shut swallow
shut swallow
naive pawn
#

well tbf the invoke function would indeed be the direct answer to that

#

it's just not a very good way (comparatively) to go about it

#

because magic strings

shut swallow
#

that's what i was wondering, since i saw both method and i was thinking oh hey either one works
invoke is good enough but i was asking if i should just do a coroutine and save myself the trouble if i wanted to mess with gravity again

#

oh and another question

#

i was thinking of implementing wall running

#

but my character is using a kinematic controller and most tutorials out there uses rigidbodies to save themselves from the trouble of simulating gravity

#

how should i approach this

mystic glacier
#

👋

#

I have an UnityEvent<float> in my code and in Inspector, I'm linking it to a method which only takes a float value

#

But it still requires me to manually input the value

#

What should I do?

#

The event: ```cs
[SerializeField] private UnityEvent<float> onValueChange;


How I invoke the event: ```cs
onValueChange.Invoke(normalizedValue); // the type of normalizedValue is float

The method: ```cs
public void ChangeSensitivity(float sensitivity)
{
GlobalData.sensitivity = sensitivity;
}

#

How I link the method (see how it requires me to input a manual value):

slender nymph
mystic glacier
#

Thank you!

weak talon
#

Hi have problem.
i have a track gameobject and on that game object i have script with a variable "track"
i am trying to assign the prefab track gameobject onto that variable but when i click play it reverts to being the gameobject in the scene rather than the actual prefab
I kinda see why, it happens because the variable i am assigning is technically itself. But i want it to be the specific prefab not "itself". How do i fix withouht having to make a gameobject in scene that stores this gameobject prefab then access it through there
seems like waste of time, surely there is an easier way to do it

naive pawn
#

you're reassigning a variable, but you don't want it to change...?

sour fulcrum
#

there is not a good direct way to do what you wanna do

#

you cannot reference the prefab asset on itself and retain the asset ref

weak talon
weak talon
sour fulcrum
#

Anything that sounds about right will probably work, not sure which will be preferable for you in this context

#

but you just can’t keep the asset reference on itself directly

weak talon
calm sierra
#

I am following this tutorial, and the clamping for the camera just isnt working at all. It also restricts me to vertical camera movement https://www.youtube.com/watch?v=f473C43s8nE

FIRST PERSON MOVEMENT in 10 MINUTES - Unity Tutorial

In this video I'm going to show you how to code full first person rigidbody movement. You can use this character controller as final movement for your game or build things like dashing, wallrunning or sliding on top of it.

If this tutorial has helped you in any way, I would really appreciate...

▶ Play video
#

I am using this tutorial because its from around the same time as 2021.3.13f

keen dew
#

You'll have to show your code

calm sierra
#

ah, right

#
public class PlayerCam : MonoBehaviour
{
    public float sensX;
    public float sensY;

    public Transform orientation;

    float xRotation;
    float yRotation;

    private void Start()
    {
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible = false;
    }

    private void Update()
    {
        // get mouse input
        float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
        float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;

        yRotation += mouseX;

        xRotation -= mouseY;
        yRotation = Mathf.Clamp(xRotation, -90f, 90f);

        transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
        orientation.rotation = Quaternion.Euler(0, yRotation, 0);

    }
}```
naive pawn
calm sierra
#

ok, ill try

#

oh goodness, the sensitivity is now really high

slender nymph
#

you need to reduce the values set for your sensitivity variables by a factor of like 100

calm sierra
#

just did, the sensitivity is alright

#

but the camera is still outside where its supposed to be and only moving up and down with no clamping

keen dew
#

compare to your code

calm sierra
#

okay, now i can look around and clamping is working but the camera still spawns outside

#

its supposed to be inside for several reasons

#

its being set to the position its supposed to be in Update(), its positioned there in the editor, yet it just places itself outside

keen dew
#

It's a really bad tutorial btw

#

It says that you have to use the proxy object to set the camera position but there's no reason for that. You can just put the camera as a child of the player and delete the script that moves the camera there

calm sierra
#

and its instantly working! thanks!

#

the reason im using it is because it was the only one that covers sliding, dashing, etc.

#

and the other one that also didnt cover these just didnt work, gravity was bad and didnt react to any changes, etc.

acoustic belfry
#

oooooh, thats it!

thank you so much

main steeple
#

ok, I try to make my character to move with the input system, and used a small usefull youtube tutorial, but it doesn't work. Can anyone help?

slender nymph
#

see #854851968446365696 for what to include when asking for help because you have not provided enough details

main steeple
#

oh, umm here is the code, errors and input manager settings that i use:

I tried changing the variable's name and capitalization but it still doesn't work.

is this enough information?

keen dew
#

You have two PlayerMovement scripts

main steeple
#

oh, right forgot about that, let me see if that fixes it

slender nymph
#

you would think that there would be errors in the IDE, it's clearly configured (despite the god awful font)

main steeple
#

oh, wait there is a second script in a folder

#

great there is the old same error again :[

wintry quarry
#

Which means it's generating a class by that name

#

This is essentially a naming conflict between the built in PlayerInput component and the one you created that is not a Component at all

#

Your code also seems to be confused about how it's using this object. You're using it as it were an InputActionAsset but it's not

main steeple
#

can you tell me it in english?

wintry quarry
#

That was English

#

It's hard to say what fix to do because you could go one of two ways

#

In any case you should rename your actions asset so it's not called PlayerInput because that's confusing the hell out of you

main steeple
#

i think i get it

wintry quarry
#

And make sure when you do that it doesn't leave behind the generated C# script named PlayerInput.cs

main steeple
#

I got it! thank you!!

#

no wait nvm

rocky wyvern
#

I am very confused

#

how the hell are we meant to rotate a quaternion in Unity.Mathematics if "Operator '*' cannot be applied to operands of type 'quaternion' and 'quaternion'"????

#

I don't see any functions for it on the scripting api

wintry quarry
#

mul(q1, q2)

rocky wyvern
#

tx

wintry quarry
#

Unity Mathematics is modeled after HLSL which uses this formulation

rocky wyvern
#

very odd choice to not be able to use the operator

#

I see

#
    {
        return quaternion(a.value.wwww * b.value + (a.value.xyzx * b.value.wwwx + a.value.yzxy * b.value.zxyy) * float4(1f, 1f, 1f, -1f) - a.value.zxyz * b.value.yzxz);
    }```
actually to be honest fair enough
polar acorn
true sail
#

!training

#

lol sorry I thought there was like a 750 hour course or something i saw earlier and this was the link for it

slender nymph
eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

true sail
#

Thanks!

slender nymph
#

it's also not a single course. the learn site is a collection of many courses

true sail
#

Yeah I love that! 🙂

slender nymph
#

if you're new though, best to stick to the learning pathways, the unity essentials pathway goes over how to use the editor and some game dev related concepts in general, then there's the junior programmer pathway that covers how to use c# in the unity engine, and the creative core pathway that teaches concepts like lighting and shading

true sail
#

I'm already slightly experienced with Unity from random tutorials and stuff. I've modeled a spider asset and put it in my game and animated it and stuff. But I want to create a menu which I've never done before, and I was thinking a might be able to find something in the site

gusty folio
#

I exported my game for mac and for some reason, the camera's really zoomed in, the camera is also a square now, and all im seeing is the blue screen in the background. It works fine in game view in editor however.

#

It keeps on flashing between white, blue, and yellow

#

even if i create a completely empty scene and export only that, this keeps on happening

#

I have no idea what's happening

slender nymph
#

this does not seem like a code issue. but you'll probably need to provide more details about your build settings and the like in a more relevant channel
#🔎┃find-a-channel

rocky wyvern
#

Anyone double check this I feel like I've made some stupid logic error somewhere
Context is I'm spawning some rocks from a volcano and want them to fly through the air to a set impact point. Doing this instead of some physics thing cause the impact and spawn points being precise and easily changable is important.

[BurstCompile]
public partial struct MoveEruptionRocksJob : IJobEntity
{
    [BurstCompile]
    public void Execute(in EruptionRockData rockData, ref LocalTransform transform, ref PhysicsVelocity physicsVelocity)
    {
        quaternion directionToImpactPoint = quaternion.LookRotation(rockData.ImpactPoint - transform.Position, new float3(0f, 1f, 0f));

        float angle = math.angle(transform.Rotation, directionToImpactPoint);



        if (angle == 0f) transform.Rotation = directionToImpactPoint;
        else transform.Rotation = math.slerp(transform.Rotation, directionToImpactPoint, math.min(1f, rockData.RotationSpeedRadians / angle));



        physicsVelocity.Linear = transform.Forward() * rockData.MovementSpeed;
    }
}
#

Blue is intended, red is what's happening

wintry quarry
#

Shouldn't it be two direction vectors?

#

Also this is a "wrong slerp"

quaint kestrel
#

I can't seem to find the input action. It gives me a null error.
private void Start()
{
_blockAction = InputSystem.actions.FindAction("OverheadBlock");
}

naive pawn
#

why not use serialized references?

quaint kestrel
#

Oh never mind it works after changing something.

#

Took me so long nothing worked but I did something now and it worked. Sorry

rocky wyvern
#

It’s set in the code I sent

rocky wyvern
wintry quarry
#

oh true

wintry quarry
rocky wyvern
#

the reason I'm using lerp here is simply because... I looked at Quaternion.RotateTowards and copied the functionality

#

I essentially want burstable Quaternion.RotateTowards()

#

but it just doesn't exist in unity.mathematics

wintry quarry
#

which actually matters in unity mathematics

#

you need to either normalize or use LookRotationSafe

rocky wyvern
#

yeah that was it

#

like i said I thought it was just some silly error but sometimes those are so hard to spot yourself without walking away and coming back xD

#

but i gotta get this done today

#

tx

rocky wyvern
#

isn't this meant to be saying that value will never reach the intended value because using something like deltaTime * speed will not ever be 1

#

meaning you will never actually reach the full value

wintry quarry
#

yes\

rocky wyvern
#

alright

#

in that case I don't think this is the same scenario because it will be 1 when the angle from current direction to intended direction is less than the rotations peed

#

that's why theres the math.min after all

#

so it doesn't overshoot

lavish dawn
#

anyone know whats going on?

neon ivy
#

I thought it'd be nice to put a bunch of events in a static class called GameEvents where I can just invoke and subscribe from anywhere. then I find out you can't invoke an event from outside the class... is there a solution for this? or maybe is there a proper way of doing what I want that I don't know about?

frigid sequoia
eternal needle
#

Or if you dont really care that things could modify the delegate, you could exclude the event keyword. Since the purpose of event is to restrict access

frigid sequoia
verbal dome
rocky wyvern
#

what you are trying to do should be done with an event channel

neon ivy
#

event channel?

rocky wyvern
#

its a design pattern

#

this might be helpful to you

#

I mean of course you do not HAVE to implement this pattern

neon ivy
#

it sounds nice

rocky wyvern
#

but your use case seems to be 'I want to relay when many things happen to many other things'

#

that is the purpose of the event channel pattern

neon ivy
#

yea

#

that's exactly what I want to do :D

#

thanks!

eternal needle
# neon ivy that's exactly what I want to do :D

This "event channel" literally is just moving the event to a scriptable object. I really wouldnt go this route either. It's never had a proper reasoning for existing other than small scale tests pretending like its cleaner. Suddenly you have assets for every unique event that needs to exist in the game

#

And it really is a misuse of what scriptable objects are

sour fulcrum
#

I think it maybe(?) might be useful in a particular environment where your working with designers and programmers but also do not have the time/experience budget to handle that relationship via custom editors/inspectors, maybe visual scripting stuff etc. but outside from that yeah

eternal needle
#

A proper implementation would be the event bus, but might be overkill here

neon ivy
#

I thought it would just be nice to have a central location that can handle events like OnTurnEnd, OnAttackSelected and OnAttackConfirmed

rocky wyvern
#

I have personally found the pattern very useful for mid size projects

eternal needle
rocky wyvern
#

perhaps because it simplifies things a little in a way that doesn't create dependencies in scene

eternal needle
#

Now with SO you just need to create assets on top of it for no reason

rocky wyvern
#

which makes multi scening waaaay waaaay easier

sour fulcrum
neon ivy
grand snow
#

Adding a public function to call an event is the way to go

#

unwise to remove the event keyword

eternal needle
#

The SO solution would literally be the same problem because you're moving the event to the SO

sour fulcrum
#

keep in mind that in general it's really worth considering if your UIManager should be able to call GameEvents.OnAttackSelected directly

rocky wyvern
#

I do think a lot of the benefit of the event channel approach is certainly psychological

neon ivy
rocky wyvern
#

orrrr ease of understanding if that makes sense

eternal needle
rocky wyvern
#

just before you ever do anything like this you need to sit down and think if its actually necessary

neon ivy
eternal needle
neon ivy
eternal needle
#

The easiest way would be just removing the event keyword

#

In that case you open up the delegate to be modified, so anything could go and set the delegate to null

neon ivy
#

yea that sounds like a no-go

sour fulcrum
#

you can't have it protected but avoid the work of protecting it at the same time

rocky wyvern
neon ivy
#

true :c

rocky wyvern
#

if you're looking at that solution and thinking oh my god that's gonna take hours then you need to seriously reconsider whether you need all of those events

eternal needle
# neon ivy yea that sounds like a no-go

I truthfully dont consider it an issue though yea I see why you might want to avoid that possibility. To me its on the same level of already being able to loop through the scene and delete every gameobject through any class. You just dont set the delegate to null because you are smarter than that

#

A public function is the common way

wintry quarry
sour fulcrum
#

and the point of a function middlemanning the process in general is that the function itself can validate that the related logic is safely in place to correctly fire that event off safely

neon ivy
#

actually if they're all separate functions I can give them separate parameters UnityChanwow

rocky wyvern
#

function is also great for debugging :)

neon ivy
sour fulcrum
#

why doesn't that make sense

#

fake player jumping through the same hoops the player is

neon ivy
#

UI is for a player to interact with

#

code calling a button's on click events is just cursed xD

sour fulcrum
#

your UIManager is doing two jobs for you

communicating between the front end of the game and the player
communicating between the front end of the game and the back end

#

treating the fake player equally might work nicely

#

and as youve said, it's not an on click event, it's an on attack selected event

rocky wyvern
#

call the script that holds those attack related events attackmanager or combatmanager or something if you think it makes more sense

wintry quarry
neon ivy
#

well that's where this idea started, and turned into "I want a central hub from where common game events can be invoked and subscribed to"

wintry quarry
#

you need another layer of abstraction in there

sour fulcrum
neon ivy
rocky wyvern
#

as much as you think it doesnt make sense that your auto play is interacting with ui then it would make just as little sense that the player is interacting with the combat system

#

player -> ui -> combat <- autoplay makes the most sense no?

neon ivy
#

yea

lean pelican
#

Using the Input System/Player Input component, how can I briefly (for the span of a Coroutine) disable only the 'Player' Action Map, but leave the 'UI' one active? I want the player to be unable to move sideways as their (2D) character is dashing, but obviously they should still be able to pause the game.

warped tusk
#

why my msg get del

slender nymph
#

!collab 👇

eternal falconBOT
#

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
Collaboration & Jobs

slender nymph
#

and that is why it got deleted probably

fickle plume
#

Read the warning. You were already linked that

wintry quarry
lean pelican
#

How do I get the correct Action Map from the PlayerInput component? I tried looking at the API but I don't get it.

wintry quarry
#

to spell it out more:

InputActionAsset asset = myPlayerInput.actions;
ActionMap uiMap = asset.FindActionMap("UI");```
lean pelican
#

GetComponent<PlayerInput>().actions.FindActionMap("Player").Disable();

#

Would that work? Provided I'm on the same GameObject as the PlayerInput.

wintry quarry
#

yes, but it's best to cache some of those intermediate things rather than fetching them fresh each time

lean pelican
#

And it actually autocompletes to InputActionMap.

lean pelican
#

Yep, it's working exactly as intended. Thanks for the help.

wintry quarry
lean pelican
#

All good. Thanks for the help^^

keen acorn
#

Halloo
I'm making a sort of vampire survivors clone, and a question crossed my mind. You see, I have an XPOrb object that is attracted to the Player object. So the xp orb will constantly get closer to the player.

My implementation for this is fairly simple:

...
float speed = 4;
GameObject player;
...
private void Update()
{
    transform.position += (player.transform.position - transform.position) * speed * Time.deltaTime;
}
...

This is just some vector magic to move the orb into the player, and it works just fine. But I was wondering whether there would be better ways to do this. For example, I could have the orb sort of point towards the player, and have it move towards that direction it faces. I'm sure this would also work, but is it better in any way?

keen dew
#

If the rotation of the orb doesn't matter then it's the same thing

#

Note that what you have now makes the orb move slower when it gets closer to the player

keen acorn
keen acorn
eternal needle
azure iris
#

how do i reference a script in the same object? im trying to get a value from another script then use that to set a playerpref

azure iris
#

thank you

summer forum
#

hello can i have some help please, my script works but theres no code highlighting, ive done everything in the tutorial to vonnect vs with unity but nothing seems to work

grave frost
summer forum
#

sure

ivory rain
#

Hihi, I literally dont' know how to code and I've already ran into a problem. I am trying to trigger OnMouseDown() on an object that has a 2d Box collider and rigidbody, and I have it put something out into the log when it triggers, but when I go into play mode I cannot get the OnMouseDown() to trigger in the first place, despite clicking on said object

summer forum
#

bro i js deleted that project opened a new one and it works now

#

so weird

#

and i even tried regenerating the files in the old one so i wouldnt have to delete and open a new one

#

ffs

teal viper
summer forum
#

guys here rb.AddForce(0,2,100 * Time.deltaTime);
Is it onlt 100 that is getting multiplied with deltatime?

#

so is it the only force thats framerate independant?

shut swallow
#

I’m trying to make a time stop mechanic for my game, I’ve seen some people turning everything into rb.iskinematic and storing the velocity as a separate variable, but is there a better way of doing it?

teal viper
shut swallow
#

Yea that makes sense

teal viper
#

Yep

shut swallow
#

Wow didn’t expect the solution to be this simple

#

But then my question become like if i want to add force

#

How would i do that on the object

#

Should I apply the force afterwards?

#

Use like a coroutine that checks for delay for time stop and apply the attack afterwards?

teal viper
shut swallow
maiden loom
#

how do i unload a scene?

maiden loom
#

it loads the scene but doesnt unload the past one

frosty hound
#

If ChatGPT couldn't solve it, it's not possible.

shut swallow
#

Lmfao

eternal needle
shut swallow
#

To my knowledge chatgpt is not using unity 6 as its basis of response because it haven’t came out yet

maiden loom
polar acorn
eternal needle
#

ah i was just typing that

maiden loom
#

i had an additive load scene but when the code ran it crated a shit load of scenes

#

making crazy lag

polar acorn
maiden loom
#

yeah i did that i fixed it

vagrant coyote
#

yo can someone help me with some enemy ai coding

eternal falconBOT
digital robin
#

https://paste.mod.gg/
Yo i wanted to ask yall something i made an enemy sprite with animations and a code but the problem is that my enemy is stuck at the walking animation and i already tried it with AI to fix it cuz its my first time using Unity. Is anyone avaible to help me with my problem?

timber tide
#

Not seeing any code ;p

#

I suggest finding some tutorials to follow via youtube

digital robin
digital robin
#

nvm it works like this aswell

stuck field
#

Not really, we can't read all that and there's no syntax

digital robin
#

okay

stuck field
digital robin
stuck field
#

There's a few animation parts in your code, none of which change the animation to walking, so that likely means none of your animations are being played in the code considering that

digital robin
#

alr

frigid sequoia
#

Probably not important, but when I drag the cursor outside the game window, it stops doing stuff like moving camera down if the mouse was on the bottom part of the screen. Is there a way to get the last mouse position inside the window so it can continue dragging even if you move out of it? Should I even worry about that?

#

I have seen many games work like that and I kinda assumed was the default thing

stuck field
#

I wouldn't say it's worth stressing over unless it ends up causing issues

frigid sequoia
#

Prob not, but I can see how that can turn extremelly annoying if playing on a window, for it is rn

digital robin
teal viper
#

Maybe in a few more years it would be feasible, but not yet. You'll just get yourself in rabbit hole with a garbage of a project.

#

To make it clear I'm talking about a serious production aimed project. Not the sort of trash vibe coding projects that plague the internet now.

frigid sequoia
#

Shouldn't be the previous scene be unloaded by default if you just do a normal scene load anyways?

#

Like anything without DontDestroyOnLoad should just be removed automatically

teal viper
frigid sequoia
# maiden loom

So... why is he doing a normal load and Async Unload???

teal viper
#

Good question. Probably because they've no clue what they're doing.

#

And they probably confused the llm too while messing around

wind lava
#

Anyone can teach me how to make inventory like rust game. I already tried to use unity free asset also watching yt tutorials but it is not working.

naive pawn
civic scroll
#

I have a question. I played my game in editor, and It didn't make any error(Also Visual Studio Code). But I can't build it because of 'Error building Player because scripts had compile errors' Why unity keeps on showing me this kind of error? Does anybody have any idea?

eternal needle
civic scroll
#

Console shows me nothing...

frigid sequoia
#

Just that they are being checked by the IDE and not Unity

civic scroll
#

Well, what should I use for checking in Unity context? Is there any extension in VSCode for that??

eternal needle
civic scroll
#

I'll try it.

eternal needle
eternal falconBOT
eternal needle
#

though id assume you would notice having compile errors when running the game in editor since you said you played it in editor

civic scroll
#

which log file should i see?

#

On the list you sent me

frigid sequoia
#

Should be showing erros by default tbh...

keen dew
#

If the build fails because of compile errors, the console should show at least the error that says compilation failed. Open the console right after the compilation failed and make sure errors aren't hidden

eternal needle
#

but yea also i shouldve checked first, your errors might be hidden. also the most common time we see people struggle with that error is when they use UnityEditor and try to include that in a build

#

can you send a screenshot of the console?

civic scroll
#

I'm not sure this would be helpful...

#

ChatGPT also told me about if endif, but not in my case.

#

just using UnityEngine;

eternal needle
#

chatgpt is as good as asking a random guy on the street. id look into your editor logs then

#

maybe some class you forgot about is using UnityEditor

civic scroll
#

You mean I should or I shouldn't?

#

[main 2025-05-19T06:43:08.544Z] update#setState checking for updates
[main 2025-05-19T06:43:08.674Z] update#setState idle

is this what you want...?

eternal needle
#

check your editor logs and search for any errors. not sure why there isnt more info in console. is there maybe more info if you click the errors themselves? havent actually had this issue in awhile so i dont remember whats supposed to show

#

your log files should have way more than just that

civic scroll
#

oh I found more up there

#

I'll try ctrl F and search for error

#

Build completed with a result of 'Failed' in 8 seconds (8157 ms)
Error building Player because scripts had compiler errors
UnityEngine.Debug:ExtractStackTraceNoAlloc (byte*,int,string)
UnityEngine.StackTraceUtility:ExtractStackTrace ()
UnityEngine.DebugLogHandler:Internal_Log (UnityEngine.LogType,UnityEngine.LogOption,string,UnityEngine.Object)
UnityEngine.DebugLogHandler:LogFormat (UnityEngine.LogType,UnityEngine.Object,string,object[])
UnityEngine.Logger:Log (UnityEngine.LogType,object)
UnityEngine.Debug:LogError (object)
UnityEditor.BuildPlayerWindow/DefaultBuildMethods:BuildPlayer (UnityEditor.BuildPlayerOptions)
UnityEditor.BuildPlayerWindow:CallBuildMethods (bool,UnityEditor.BuildOptions)
UnityEditor.Build.Profile.BuildProfileModuleUtil:CallInternalBuildMethods (bool,UnityEditor.BuildOptions)
UnityEditor.Build.Profile.BuildProfileWindow/<>c__DisplayClass44_0:<OnBuildButtonClicked>b__0 ()
UnityEditor.EditorApplication:Internal_CallDelayFunctions ()

I guess this is the most recent error log. I have something more down here, but I think it doesn't have a direct relation to this.

#

Can you figure out the problem???

stuck field
#

That error is quite useless in terms of figuring it out

civic scroll
#

Oh...

stuck field
#

Just tells us the build failed, other errors will say why

eternal needle
#

that one does indeed just saying it started to build then there is like 6 lines just relating to a logging statement

stuck field
civic scroll
#

yes

stuck field
#

Then you need to wrap it in #if

eternal needle
stuck field
#

Oops

naive pawn
#

do you have any using UnityEditor; or #if UNITY_EDITOR?

civic scroll
#

Yeah I heard about chatGPT, but there's no using UnityEditor; in mine

naive pawn
#

just disregard whatever chatgpt told you

civic scroll
#

If you need, I will get my code capture

naive pawn
#

what about the second one? or any #if in general?

naive pawn
civic scroll
#

copy and paste?

naive pawn
#

right now you have the tools to search through your project, better than we do

#

your ide has a "find in project" feature

eternal needle
#

is there nothing else in the log files though?

naive pawn
#

search for UnityEditor or #if in /Assets

civic scroll
naive pawn
#

do you have anything that starts with #? ie #if, #endif, #ifn kinda stuff

civic scroll
#

ok

stuck field
#

Does #ifn do if not?

civic scroll
#

fixed4 PixShader(pixel_t input) : SV_Target
{
UNITY_SETUP_INSTANCE_ID(input);

        float c = tex2D(_MainTex, input.atlas).a;

        #ifndef UNDERLAY_ON
        clip(c - input.param.x);
        #endif

        float    scale    = input.param.y;
        float    bias    = input.param.z;
        float    weight    = input.param.w;
        float    sd = (bias - c) * scale;
#

this?

stuck field
#

Code samples won't help

civic scroll
#

Sorry, I'm a total noob for this...

stuck field
#

Sometimes they do, but is there any more?

eternal needle
#

i have no clue about shader code honestly but if thats not your code then its likely not the issue. Hopefully

#

Id really just dig through the logs instead

#

if you have 3rd party assets they might use #if and other conditionals, you can ignore those

#

unless they were made poorly

civic scroll
#

This is quite long

#

Build Finished, Result: Failure.
##utp:{"type":"PlayerBuildInfo","version":2,"phase":"Immediate","time":1747638607497,"processId":19948,"steps":[{"description":"Preprocess Player","duration":187},{"description":"Prepare For Build","duration":10},{"description":"ProducePlayerScriptAssemblies","duration":7663}],"duration":7860}
Unloading 1 Unused Serialized files (Serialized files now loaded: 0)
Loaded scene 'Temp/__Backupscenes/0.backup'
Deserialize: 4.634 ms
Integration: 362.566 ms
Integration of assets: 0.003 ms
Thread Wait Time: 0.035 ms
Total Operation Time: 367.237 ms
Unloading 1 unused Assets / (361.8 KB). Loaded Objects now: 8972.
Memory consumption went from 366.1 MB to 365.7 MB.
Total: 28.441400 ms (FindLiveObjects: 0.636400 ms CreateObjectMapping: 0.291900 ms MarkObjects: 27.336900 ms DeleteObjects: 0.174300 ms)

#

or this

eternal needle
#

do you have a lot of code in this project, or by chance are you trying to build like one file. I can make a compile error and test what output i get

civic scroll
#

just three scripts in this. because I'm learning and testing.

eternal needle
#

honestly it might just be easier if you send the scripts then. !code

eternal falconBOT
eternal needle
#

but lets maybe make a thread for this

civic scroll
#

Where should I?

#

Oh

#

Ok

eternal needle
#

yea just send the code in there

shrewd swift
#

im wondering if there is a setting i missed to make rider properly show XML documentation on mouse hover

#

(only broken for unity types, i guess its because we only have source "cache")

shut swallow
#

I have a variable that controls the gamestate (simple boolean) and I want it to be accessed by all objects (non-player), would it be good to declare a global variable or something else

#

I know that global variables are a bit weird to use and implement

keen dew
#

Also impossible in C#

#

You can declare any field static and access it anywhere through the class

#

What you're trying to do is usually solved with singletons

north kiln
shrewd swift
#

thanks, this fixed it

brazen crescent
shut swallow
#

and call that script when i need that component

brazen crescent
#

I would do something like this

    using System.Collections.Generic;
    using UnityEngine;
    
    [CreateAssetMenu(fileName = "Game", menuName = "Gamestate")]
    
    public class Gamestate: ScriptableObject
    {
    
        public bool gameState;
    
    }

and then in your other scripts create a public variable called Gamestate currentGameste
And assign the ScriptableObject there

#

but be careful with SOs, they don't get reset when you exit playmode, so you need to add a simple logic at its enable to reset itself

sour fulcrum
#

respectfully this just seems like using SO's incorrectly for no apparent benefit?

brazen crescent
#

Can you elaborate why you think that? I'm using Scriptable Object variables for a while and they seem to be working great

#

ofcourse there are other ways to handle the problem above

sour fulcrum
#

As you mentioned your not meant to handle runtime values in SO's like that. I don't know what benefit chucking it in a reference based scriptableobject is providing rather than just singletons or statics

keen dew
#

you could just use gameobjects and not have to be careful about all the potential side effects of SOs

brazen crescent
#

as I said, you can use a singleton for the problem mentioned above, but in my opinion a SO variable is better

shut swallow
#

I would need to actively update this function in runtime and would be the only instance in my game so I am leaning towards using a singleton rn

#

I can see the SO being a solution but im not sure about the downsides

brazen crescent
#

go ahead and use a singleton then its not bad! every "pattern" has its downside/upsides ofc

shut swallow
#

quick question

#

It's better to make an external script for this singleton class right? Do I script the singleton as a boolean only or is it better to make the entire behavior within the class?

brazen crescent
#

Yeah make a different script called GameState where this will be a singleton, and call it from any other script you want using GameState.Instance
Its better to not combine classes to be easier to debug later on

alpine fog
shut swallow
#

whenever I call the singleton

shut swallow
brazen crescent
shut swallow
brazen crescent
sour fulcrum
#

inspector visualisation is fair. not sure how SO's would be more coupled in this context?

brazen crescent
#

SOs are assets, not scripts, so you don't have to reference ScriptA from ScriptB (like you would if you create a GameManager class with a static)

brazen crescent
sour fulcrum
brazen crescent
#

you are referencing the SO, you make a variable of that SO in the scriptA, you just don't have to access a script (as that script may not exist in the scene)

sour fulcrum
#

script != monobehaviour

#

so's are scripts just as much as monobehaviours are

#

MySOGameStateRef myRef

void Function()

if (myRef.gamestatevalue)

void Function()

if (MyStaticGameStateClass.gamestatevalue)

your still gonna be referencing the value of another script via code regardless

brazen crescent
#

What I'm saying is that the SO doesn't live in the scene, so you can access it from anywhere by assign it in the inspector, you don't have to have a script attached to a gameobject to get that value, which makes it great for testing in test scenes

sour fulcrum
#

sure but i was asking why not use static values

#

if its just the inspector thing thats fine i was just confused

brazen crescent
#

with static variables you create a dependency on the script itself with the static variable, while with SO Variable you are referencing the data itself

fair shore
#
 public void OnDrag(PointerEventData eventData)
 {
     Debug.Log("Dragging");
     Vector3 screenPoint = new Vector3(eventData.position.x, eventData.position.y, Camera.main.WorldToScreenPoint(transform.position).z);
     transform.position = Camera.main.ScreenToWorldPoint(screenPoint);

 }``` I want to drag the object but not the object's child.
sour fulcrum
#

sos are scripts

brazen crescent
#

I think we are going in circles, lets leave it at singletons/statics have their uses, and SOs have their own

sour fulcrum
#

i don't know if you are using the term script accurately

polar acorn
# sour fulcrum sure but i was asking why not use static values

Static values are not tied to any specific instance. They don't get reset when something is destroyed and recreated, once set, they remain in memory for the entire duration of the program, they're shared between all objects everywhere.

In general, it's better to have a static reference to an instance of a class (usually Singletons) than a static field, because that gives you freedom to dispose of a variable when it's not needed, reset it, serialize it to disk, view it in the inspector, etc.

polar acorn
dreamy gyro
#

Can anyone help me? no mater the project or version I get a grey screen,I can only see gizmos, on the scene editor and the game view. I tried deleting my ~/.config/unity3d folder, and reinstalling unity, but nothing seems to work.

marble hemlock
#

!code

eternal falconBOT
marble hemlock
#

ty unity dyno bot

#

https://hastebin.com/share/levazodisu.csharp

if anyone could take a look, i have a problem with this script.

i was basically trying to have it so that when they crouch (that method is at the bottom of the script) they would slow down.

#

i had reasoned that multiplying it by something less than 1 would make the movement speed smaller, but it basically had 0 effect. it wasnt until i started putting negative numbers, that it started slowing down

#

as long as the negative number did not have an absolute value greater than the walk speed, it would slow down

if it did have a greater value, then i'd just start having reversed controls

tawdry valley
#

Hi, i have a custom package on github also it's depended to another package which is on github. When i tried to install my custom package it couldn't find it's dependency. What should i do?

i am getting this error : Expected a 'SemVer' compatible value.

Example package.json

{
  "name": "com.yourname.mypackage",
  "version": "1.0.0",
  "displayName": "My Custom Package",
  "description": "A description of your package.",
  "unity": "2021.3",
  "dependencies": {
    "com.other.dependency": "https://github.com/username/other-unity-package.git#1.0.0"
  }
}

marble hemlock
#

does anyone know which part is the faulty bit?

grand snow
grand snow
#

openupm exists but ofc those are all public

tawdry valley
#

i can install my base package to unity but i can't other one which is depended to base. Still doesn't get it what to do

polar dust
#

I imagine if you copy these same steps, but substitute the UPM registry lines with your own, that should install just the same

#

all its doing is telling the package manager what address to look in

polar acorn
hexed hare
#

Is there any way someone can fix my script so that space bar allows my player to jump? I cannot get it to work, but i have the rest of it finished

#

I can send it to whoever is able to fix it

polar dust
#

best chance youve got is to post the code in the first place

main spade
#

Trying to make a mechanic where the player can bust through breakable objects via tags. Right now the collision Hanlder script works just fine, but I wanted the object to shatter and break when collided with. I made a separate break script but the issue is that the breakable rock in this case is shattering when I load into the level when it should only do that when colliding. I've so far tried to call it when it only collides with the player(has a "Player" tag), but the issue persists. Gravity is turned off for the yellow rock(Breakable object in question).

wintry quarry
median hatch
#

super useful

#

easy to access and non-programmers can easily edit the data too

quick pollen
#

so I am experiencing a really weird issue

        if (other.gameObject.CompareTag("Wall")) //if it's a wall, bounce off
        {
            rb.velocity = Vector3.Reflect(currentVelocity, other.GetContact(0).normal);
            transform.rotation = Quaternion.LookRotation(rb.velocity.normalized);
            rb.angularVelocity = Vector3.zero;
            if (bounces > 0)
            {
                bounces--;
                AudioHandler.Instance.PlaySound("Bounce");
                if (bounceParticle != null)
                {
                    ParticleSystem bounce = Instantiate(bounceParticle);
                    bounce.transform.position = bounceParticle.transform.position;
                    bounce.gameObject.SetActive(true);
                    bounce.transform.parent = null;
                    Destroy(bounce, 1);
                }
            }
            else if (gameObject.activeSelf)
            {
                DestroyDusts();
                if(pool != null)
                    pool.Release(gameObject);
            }
        }```
i have these lines for making a projectile bounce off of a wall, if it has a bounce left
#

problem is for some reason, in one scene, it works, and in the other one, it doesnt

#

all the variables are the same

wintry quarry
quick pollen
#

I use a single prefab over all scenes

quick pollen
#

so I tried looking at the rb.velocity before and after the reflect

#

nothing wrong with it

wintry quarry
quick pollen
#

except that it isnt somehow

wintry quarry
#

Add Debug.Logs to your code

quick pollen
#

because it is moving

wintry quarry
#

prove it

#

prove it with logs

#

that's what will matter

quick pollen
#

wtf

#

sometimes it is, sometimes it isnt

#

but theres no visual indicator

#

maybe the issue is that it collides with the wall, and so the velocity becomes 0?

#

sometimes it just does the check late?

brave robin
#

When something works in one scene but not in another it often means there's a separate or duplicate script/object that is influencing it

wintry quarry
#

it always does the check late. OnCollisionEnter happens after the collision. If you want an accurate bounce without losing speed the best thing to do is either:

  • record your "lastVelocity" in FixedUpdate and use that along with the hit point and normal to reflect it in OCE.
  • use the information from the collision including relativeVelocity along with the hit point and normal to accuirately reflect the velocity.
#

I also recommend against modifyinbg the Transform directly like you are doing with transform.rotation here

wintry quarry
quick pollen
#

also fuck I just ran the game without rebaking the fucking navmeshes

#

why tf does it cause a memory leak

#

fuuck

#

so annoying

quick pollen
rocky canyon
#

settting the transform directly doesn't use physics engine and you're basically teleporting

by rotating the rigidbody w/ a rigidbody function it does

wintry quarry
#

it generally leads to unpleasantness for the user

main spade
#

I'm trying to make a dash sound effect when a dash ability is being performed. Audio clip by itself works fine but it isn't playing when the dash is being performed:

{
    if (canDash && !isDashing)
    {
        StartCoroutine(PerformDash());
  
    }
}

private System.Collections.IEnumerator PerformDash()
{
    canDash = false;
    isDashing = true;

    audioSource.PlayOneShot(DashSFX);

    Vector3 dashForce = transform.right * (dashDistance / dashDuration);
    rb.AddForce(dashForce, ForceMode.VelocityChange)

    yield return new WaitForSeconds(dashDuration);

    isDashing = false;

    // Start cooldown 
    yield return new WaitForSeconds(dashCooldown);
    canDash = true;
}```
whole osprey
main spade
sour adder
#

You should try set

isDashing = true;```
before starting the coroutine.

It waits one frame to activate, so maybe you start more than one. I think.
whole osprey
sour adder
#

When you do StartCoroutine, it doesn't run before the next frame, it is added to a list of things to run the following frame... But not sure if that is the issue.

grand snow
#

I think its depends on how you start it actually

polar acorn
main spade
# whole osprey Is the audio source being used for other things? PlayOneShot won't stop anything...

the audio clip itself is being used once aka the dash. It isn't meant to override any other audio playing and is meant to be used in tandom since its a lot shorter compared to the other audio clips being played. I do have some SerializeFields of audio clips which this one is [SerializeField] AudioClip DashSFX; , which utilizes AudioSource audioSource. The DashSFX sound itself is currently selected in the editor

#

All the other audio clips work fine except for that one

whole osprey
#

Hmmm... well, if you're only using that audio source for this one clip, that's probably fine. No errors or anything, you just can't hear it?

Want to show your audio source settings? Only other place I can think of it might have gotten messed up on accident.

main spade
whole osprey
#

Try just stopping it before playing to test that issue. audioSource.Stop();

main spade
#

For example, I use audioSource again when making mainEngineSFX(the sound that plays when the player moves) via if (!audioSource.isPlaying) { audioSource.PlayOneShot(mainEngineSFX); }

main spade
sour adder
jolly stag
#

So I'm having a curious issue if anyone can help, the issue is that in a 3D game my player gets stuck in the air when jumping at a wall before slowly coming back down. I'm using transform for sideways and forward movement but the jump is done through a rigidbody, I know I can fix this by using a physics material and turning Dynamic Friction to 0 but then I just slide off any hills in the game. Thank you for any help :)

hidden fossil
#

guys what do i do about this if (MusicSource != null && EnemyDealDamageToBase != null)
{
Debug.Log("Audio is going to play!");
MusicSource.clip = EnemyDealDamageToBase;
MusicSource.Play();
}

#

im getting the debug log that the audio is going to play

eternal falconBOT
hidden fossil
#

but i dont hear it

wintry quarry
hidden fossil
#

in the update()?

wintry quarry
#

Update runs every frame

#

if the code is in Update, it's running every frame

hidden fossil
#

its not in update

wintry quarry
#

where is it?

hidden fossil
#

private void DealDamageToBase()
{
if (levelManager != null)
{
levelManager.Lives -= damageToBase;
}

        if (MusicSource != null && EnemyDealDamageToBase != null)
    {
        Debug.Log("Audio is going to play!");
        MusicSource.clip = EnemyDealDamageToBase;
        MusicSource.Play();
    }
}
polar acorn
#

So perhaps you should post the full code so there's context as to what is calling it

wintry quarry
#

And this doesn't tell us anything

#

we have no idea where this method is running from

hidden fossil
wintry quarry
#

looks to me like you're destroying your audio source immediately after calling Play

polar acorn
#

A destroyed object won't be making much noise

hidden fossil
#

so i just have to delay the destroygameobject and then it will play?

wintry quarry
#

or play the sound from a different object

#

or use PlayClipAtPoint

fast vine
#

Im very new and sorry if I shouldn't ask this here but can someone please tell me if their is a way to resolve this so I can work on my game

polar acorn
#

Probably near the end of the log file

fast vine
#

I see these at the end of the info-log, is this what you mean?

ashen arch
wintry quarry
fast vine
wintry quarry
#

ideally both

fast vine
wintry quarry
#

which file

fast vine
#

well its not just 1 file but the whole thing isn't on my pc

wintry quarry
#

wdym by "the whole thing"?

#

Maybe sharing the full error message here would be helpful

fast vine
#

alright

wintry quarry
#

(is the last part intentionally duplicated?)

fast vine
#

no its not I didn't mean to do that

wintry quarry
#

so it looks like you probably just gave the wrong filepath to the hub

fast vine
#

how would I go about fixing that?

wintry quarry
#

re-add the project to the hub with the right path

valid palm
#

Excuse me, I need help. I made a webgl game, in said game I put 2 UI panels with messages. Both work on editor. But, when I build the game and play on itch io, the second panel wont show up, in fact, the game goes on as it was there (when a message spawns, the CC stops until its closed).

wintry quarry
#

Which means you didn't anchor your UI properly

valid palm
#

but its the same res and config as the first panel

jolly stag
wintry quarry
#

You can set the editor game view resolution freely

valid palm
#

okay

fast vine
wintry quarry
fast vine
#

I have the game and all the branches on my unity acc but just not on my pc is their way for me just to download those onto my pc

valid palm
#

works fine in every res

fast vine
wintry quarry
#

ok and what do the logs say this time?

fast vine
#

ok just to check these are the only ones that should be here right?

wintry quarry
#

yes

fast vine
#

alr cool

wintry quarry
# fast vine alr cool

by the way you never really showed it but - does the C:\\Users\\trevo\\Violet Rot folder exist at all?

zinc agate
#

hey i was wondering how to fix this issue. In the events tab, i cant seem to find any functions although the code matches everything within the tutorial im following.

wintry quarry
fast vine
#

I gotta download all the stuff from my unity acc and make a copy of it

wintry quarry
# fast vine nope....

in the hub you need to click the Gear Icon - Go to the Projects tab - and make sure the project location default is set to a folder that actually exists

wintry quarry
#

you dragged the script itself in

#

you need to drag the object that has the script on it

polar acorn
zinc agate
#

omg

#

in the tut it literally says drag the script

#

thank u guys!!1

wintry quarry
zinc agate
#

lmaoo

fast vine
#

praetorBlue its all working now thanks a lot you've been a great help

frigid sequoia
#

Can it be that an OnPointerUp and a OnPointerExit trigger on the same exact frame on the same button???

#

I am playing a sound when the pointer is Up and he cursor was over the image, but sometimes, and just sometimes, if you are fast enough, you can make the sound play without pressing the button

final forge
#

Hello, I'm trying to have one Monobehavior script handle keyboard input, where each keypress check in update will just invoke an event (is this the correct term?). Is this a bad way? Or should I just put the keyboard i/o in the class where the inputs are actually used

wintry quarry
#

Is there a specific reason or use case that you want to do this for?

final forge
#

no specific use case

wintry quarry
#

I would avoid adding complexity to the code for no tangible benefit

final forge
#

oh i didn't know it was more complexity

wintry quarry
#

if there's some benefit like you want to have inspector-swappable behavior or something else, then go for it

final forge
#

for me it was easier to think about with using events

wintry quarry
#

YOu could switch to the new input system

#

which supports event-based input handling out of the box

final forge
#

oh cool I'll take a look

wintry quarry
#

it has a learning curve, fair warning 😉

stray oyster
#

Hi, I am loading scenes additively and asynchronously, but I need to do a transform on the root game objects before the first physics frame, relative to the position and rotation of the scene (technically the root game object of the scene) that triggered it. In the loading scene's awake function, I get the triggering scene's root game objects, then have to load a script, then read the list describing the relative neighboring scenes.

I was wondering if there was an easier way. I'd like to have it the triggering scene do the transform before the scene loads in the first frame but with async and waiting I feel like that is a bit finicky.

wintry quarry
fringe moat
#

Hello!
I'm banging my head against the wall and desperately need someone to help me 🥹

I'm trying to create an object that creates the battle backgrounds for my game (it's for a 2D side-view battle type RPG).

  • The way it works is that I have an object on scene called "Battleback", and a prefab called "BattlebackLayer".
  • The prefab has a Sprite Renderer component, but no sprite assigned to it.
  • Once the game starts, I initialize several Background compositions on BattlebackLibrary
  • After Initialization, Instantiate BattlebackLayer objects on a for loop. Assign sprite, change name and sorting order.

Result: Everything works fine, except for the Sprites, which are never loaded. I have no idea why, can anyone give me a pointer on what I'm doin wrong?

https://paste.mod.gg/brodombunwrf/0

wintry quarry
#

they are null?

fringe moat
#

When I playtest, no sprite is assigned

wintry quarry
#

If Resources.Load is returning null, then you didn't put them in the right place in ytour project for use with Resources.

#

Anyway - to be honest this seems like a misuse of Resources.Load. Since you're essentially just hardcoding these paths - it would probably be better to just populate the sprite references in the inspector

#

Then you don't have to go and change the code whenever you want to add/change/remove any of these things.

fringe moat
wintry quarry
fringe moat
wintry quarry
#

it's all hardcoded

fringe moat
fringe moat
#

which are initialized at the start

#

other than that, it's supposed to be dynamic

frigid sequoia
#

You shouldn't create a Resources folder unless you actually need it, it just makes it more complex for no real reason

#

Just assign the sprites you want to use to a list manually

wintry quarry
#

because you're just hardcoding the paths

#

you might as well assign the sprites in the inspector

fringe moat
#

Well, this is just the first version of the script haha, I haven't even gotten it this to work, I can only start thinking about scaling after I get this working at least

fringe moat
#

That way I don't need to load from resources?

frigid sequoia
#

Rule of thumb, if you can avoid calling something for a folder path, you do that, 100% of the time

stray oyster
wintry quarry
#

it would be like:

public class Level : MonoBehaviour {
  public static Action<Level> OnLevelLoaded;

  void OnEnable() {
    OnLevelLoaded?.Invoke(this);
  }
}

public class WorldManager : MonoBehaviour {
  void Awake() {
    Level.OnLevelLoaded += HandleNewLevel;
  }

  void HandleNewLevel(Level level) {
    level.transform.position = whatever;
  }
}```
#

quick and dirty example

stray oyster
#

I think I got it, thanks again

wind hinge
#

Why's my brand new Unity 6 project stuck at 60fps in the editor playtest

#

Even if that's meant to be vysnc I have a 144 Hz monitor

wintry quarry
wind hinge
#

Brand new project haven't done anything to it

#

Created 30 seconds ago

wintry quarry
wind hinge
#

That has nothing to do with it

wintry quarry
#

select a frame

wind hinge
#

Its probably some bs like Armoury crate or Gsync on my laptop

#

yup

#

armoury crate silent mode

fringe moat
fringe moat
#

How do you usually handle the gap when scrolling a background-type object?
This method usually works for me on other engines, but it's producing a small gap in Unity. Anyone have any tips?

` foreach (var layerGameObject in createdLayers)
{
var layerVars = layerGameObject.GetComponentInChildren<BattlebackLayerVariables>();
if (layerVars != null)
{

            Vector3 pos = layerGameObject.transform.localPosition;

            if (layerVars.xSpeed > 0 && pos.x > layerVars.width * 1.9f) { pos.x -= layerVars.width * 3f; }
            else if (layerVars.xSpeed < 0 && pos.x < (layerVars.width * 1.9f) * -1) { pos.x += layerVars.width * 3f; }
            else { pos.x += layerVars.xSpeed * Time.deltaTime; }

            pos.y += layerVars.ySpeed * Time.deltaTime; // incomplete
            layerGameObject.transform.localPosition = pos;
        }`
wintry quarry
fringe moat
#

Yeah! Is it causing it?

wintry quarry
#

no it should be fixing it

fringe moat
#

I thought turning on Pixel snapping could fix it, but no luck either.

fringe moat
#

I got it!
I moved this: pos.x += layerVars.xSpeed * Time.deltaTime; outside of the else statement—I guess, because it was part of the conditional structure, the movement skipped a frame whenever the object was repositioned, causing it to stay one pixel behind.

digital lava
#

hello im learning unity 6.1 and im having trouble making a rocket prefab move across the map, could anyone kindly tell me what im doing wrong? im following the tutorial and it doesnt seem to be working

#

its spawning but standing still

wintry quarry
#

also make sure there are no errors in the console when running as well

#

Actually

#

there's no way you followed the tutorial properly here

#

you are getting the Rigidbody from the prefab

#

instead of from the newly instantiated rocket

digital lava
#

thank you sir

#

i figured it was something obvious

wintry quarry
#

so you're basically trying to add a force to a prefab that lives in your project folder instead of the actual rocket you created in the scene

digital lava
#

much appreciated

shut swallow
#

under what case do you use singletons over events

eternal needle
shut swallow
# eternal needle They solve entirely different things, there is no using one over the other

I'm trying to implement a pseudo-global variable to see if timestop was triggered (which effects everyone excepts the player)
I think both methods work in this case with different implantation (singleton to dictate when timestop is triggered and handle the event universally vs events which allows me to listen to the event when it happens and control the behavior directly)

#

I'm thinking which one i should pick over the other

eternal needle
# shut swallow I'm trying to implement a pseudo-global variable to see if timestop was triggere...

This still isnt a case of choosing singleton vs events.
Let's say you go with a singleton here. The only thing this does is give you a static reference to an instance of an object. How do you now notify everything that "timestop was triggered"
Now compare this to if you wanted to only use events. An event notifies all subscribers that something happens. But where does this event live? Like what class is it in, what instance is it in?

#

You could use BOTH a singleton and event here

timber tide
#

I would think pausing the update would suffice already

#

or w/e loop you're doing it in

shut swallow
#

I'm thinking of storing the velocity and releasing it if any moveable object was paused within the period

#

so simply pausing update wouldn't suffice

#

which means the object itself need to know when timestop was triggered by the player

timber tide
#

some custom physics? Your velocity shouldn't just disappear if you pause the loop

shut swallow
#

I'm a bit confused

eternal needle
timber tide
#

If we're talking rigidbodies I'm pretty sure screwing with even the timescale shouldn't result in wrong velocities

shut swallow
#

the player is kinematic, I haven't exactly decided on the other objects (like enemies) but I wanted to have the ability to apply knockback by the player attacking within timestop, and modifying the original velocity when the knockback is applied

eternal needle
#

Storing the velocity is pointless because when the timeScale is 0, their movement per update or fixed update should eventually be multiplied by 0 and thus not move

#

Even if it's a custom timescale, your objects should all be accounting for this scale in their movements at all times

shut swallow
#

so essentially when I trigger in my controller script when key down, I set the time scale to 0 to make the same effect

#

my player should still be able to move even in timescale 0, because it's kinematic correct?

eternal needle
#

You should really try it and see how it works when timescale is 0. If anything is moving, that's because you arent accounting for delta time at all

#

Kinematic objects dont move by themselves, you must have some code moving it

shut swallow
#

because my character is kinematic

timber tide
#

though if you do wanna have some deterministic rigidbodies then storing it all is ideal

#

then you can do like rewind stuff for funnsies

shut swallow
#

yea thats the idea, ragdolls and more time manipulation funnies

elder raptor
#

Hey, how do I know where this error is triggering from?

eternal needle
elder raptor
#

I get these errors the moment I run the game. They don't break anything, but I want to get rid of it LeGasp

timber tide
#

I mean just storing the rigidbody state in general, not so much just pausing

eternal needle
shut swallow
elder raptor
eternal needle
#

Your error is under the UnityEditor code so unless you wrote editor code, it's not your code that's the issue. Though i dont specifically know what you can do to fix that

shut swallow
shut swallow
#

my understanding is that you have some class or object reference not called

elder raptor
#

I didn't write any editor-related code

elder raptor
#

I tried debugging, as the codes are quite simple. And saw no null references anywhere LeGasp Maybe I will restart the editor

shut swallow
#

like this

elder raptor
#

Ohh, I see. Will keep that in mind!

shut swallow
#

you'll have to initialize your scripts if you call them

elder raptor
#

It was editor issue, I closed and re-opened the project, it stopped showing up

elder raptor
#

Yeah

shut swallow
#

game is running fine?

elder raptor
#

Yes it is

shut swallow
#

editor issue then

#

lmfao

elder raptor
#

Yeah XD

eternal needle
#

As I wrote above, yes it's not an issue with your code

elder raptor
#

Yessir, thank you!

eternal needle
#

Usually when you see strange editor errors, close and reopening should fix it. Or in the odd case it says something about nodes/graph then resetting layout might work too

elder raptor
#

I see, will keep that in mind

eternal needle
#

If it persists after closing then you have a real issue on your hands

shrewd swift
#

how is ticking managed by the engine ?
since Update (and so on) arent virtuals, i imagine the engine gets them using reflection

im asking this because i have a high amount of objects running stuff on tick and i am wondering if i can save a bit of frame time if i have 1 manager ticking for all those entities

#

so in simpler words: what is the ticking overhead

burnt vapor
#

If you instead have a single Update method which informs your components to tick, it makes quite a big deal in performance compared to having Unity call all of them

#

However, consider doing this only if it makes sense complexity wise. If you can have a parent tick its children it makes a lot mroe sense than having a base component that informs veeryhting in your application. It's unlikely that works better anyway.

shrewd swift
#

thanks for the insights, since its a manager it makes sense for me to have it managing ticking its entities

shut swallow
grand snow
#

monobehaviour events are called directly from engine native code. Its able to interface with the CLR

tepid summit
#

something tells me i may have made a mistake

#

what did i do