#💻┃code-beginner

1 messages · Page 829 of 1

naive pawn
#

oh, weird inspector stuff

#

terrifying...

manic vector
#

☠️

naive pawn
#

if you change it back, do you get the same issue?

manic vector
#

Yes, changing it back breaks it again

#

Caching was actually what the first guy thought, so I regenerated my library file and that didn't fix it

naive pawn
#

i'd guess something's messing with that specific name then. i don't think it'd be unity itself though

#

that's definitely out of my expertise though

#

if you want to debug further yourself i guess you'd test it in different files next

sour fulcrum
#

shot in the dark basketball would be to double check that there isn't any antivirus stuff going on or installing the project in a onedrive folder or something

manic vector
red igloo
#

Here is my movement code, when using a controller slightly moving the left stick in any direction should result in slower movement and pushing it fully should result in full speed. How can I achieve this? I remember having this exact same code a few months ago in a different project and it would work but not anymore for some reason.

    {
        Vector2 input = Vector2.ClampMagnitude(currentInput, 1f);

        Vector3 camForward = myCam.transform.forward;

        Vector3 camRight = myCam.transform.right;

        camForward.y = 0f;

        camRight.y = 0f;

        moveDirection = (camForward.normalized * input.y + camRight.normalized * input.x).normalized;

        float currentSpeed = isGrounded ? moveSpeed : airSpeed;

       rb.AddForce(moveDirection * currentSpeed, ForceMode.Acceleration);
    }
polar acorn
#

So, you're always moving at moveSpeed or airSpeed

#

You might want to consider ClampMagnitude like you did for the input itself instead of normalizing it

red igloo
lean summit
#

I am trying to make a game where the GameObject doesn't fall off the plane using vector3. I've done it this way and it works but depending on my fps the barrier isn't exact. Is there be a better way of doing this?
(Red highlight is the barrier and movement code)
Video for reference:

radiant voidBOT
wintry quarry
naive pawn
#

instead of "stop moving once you're past this point", think of it as "move only to this point", ie limit the final position
using physics to handle that logic could also be a choice

wintry quarry
#

yep using physics and having colliders there is another option

lean summit
wintry quarry
#

no

#

clamp is a mathematical function

#

to keep a value between two other values

lean summit
#

Oh alright, that would be extremely useful

wintry quarry
#

the idea is:
instead of condionally translating, just always translate. Then find the clamped position and move the object there

#

e.g.

transform.Translate(Direction * movementSpeed * Time.deltaTime);
Vector3 clampedPos = transform.position;
clampedPos.x = Mathf.Clamp(currentPos.x, leftBound, rightBound);
transform.position = clampedPos;```
lean summit
#

Wow that is so much more better

#

thanks

#

Mathf is just math with floats I assume?

naive pawn
#

you could also add to the current position directly rather than going through transform, that's also an option

wintry quarry
naive pawn
#

so you wouldn't have to juggle it through the transform and back

naive pawn
neon sable
#

guys, i am losing my mind here

#

i have things plugged to my pc that is affecting my getaxis, but even when unplugged unity is still acting like they exist, or i have something that is affecting it

#

how do i remove all other input apart from keyboard/mouse from my project

naive pawn
#

check the input debugger

solar hill
#

this sounds a bit like an xy problem

naive pawn
#

ah wait, getaxis

#

yeah no clue how to debug the input manager

neon sable
naive pawn
#

the input debugger i'm referring to is for input system

naive pawn
# neon sable

is it just that they're keeping the same value as when you unplugged them?

neon sable
#

yeah

naive pawn
#

seems like a pretty generic issue, could google about that probably

neon sable
#

lol

#

i mean bro i wouldnt be here asking about it if google told me

solar hill
#

after unplugging the stuff from your pc

#

did you restart it?

neon sable
#

i dont wanna restart, i have alot of things open and dunno what i'll lose if ill restart

#

i figured there'd be an input option in the settings or something

neon sable
#

i saw a for loop too of like just looping through the devices and disabling everything apart from kb+m

neon sable
#

but thats hacky and i dont wanna do it

#

unity is kinda aids tbh i have more luck designing my own engine in C

naive pawn
#

nobody's forcing you to use unity

neon sable
#

are u good bro

solar hill
#

are you?

neon sable
#

i am, this guys just useless, being super condescending and giving absolutely no help

#

like why even type

solar hill
#

how is giving no help?

#

he showed you a solution

neon sable
#

this is a single solution for a single device

solar hill
#

you havent given us much info to go off of

#

plus you refuse to restart your pc for some reason

neon sable
#

okay with all due respect

solar hill
#

what are you expecting us to do here for you

neon sable
#

i would like someone whos had this issue to help me

#

you clearly don't know

#

and thats okay

#

but going back and forth isnt solving anything

naive pawn
#

most people here would be using inputsystem anyways lol

#

that's besides the point though

solar hill
#

nobody is going to show up here with a singular magic solution

#

not without you giving us more information and context

neon sable
#

all im asking is "where is the settings to enable/disable input devices"

#

this is all i need to know

#

no back and forth needed for this answer

naive pawn
#

are they even exposed for the old system

neon sable
#

wym

solar hill
#

youre using the old input system

#

not the new one, which does have that option

naive pawn
#

if you're seeing code involving InputDevices, that's for the new system

neon sable
#

i will get to the new input system at some point im sure, but surely theres a setting in the project settings to enable/disable input devices

naive pawn
#

neither the Input api docs nor the Input Manager manual reference any method to reference input devices directly

#

there is the ResetInputAxes that was mentioned in the forum i linked you. could give that a shot

neon sable
#

ill try it but it seems even in the thread it doesnt work for him

#

seems it resets it for 1 frame

#

nvm it doesnt allow for any movement now

#

like yeah my entity is no longer moving, but now it cannot move at all

solar hill
#

Tbh this is why they made the new input system to begin with lol

#

solve headaches like this and makes the entire thing streamlined

naive pawn
neon sable
naive pawn
#

but yeah before the new input system was a thing i heard a lot about wrapping the old input manager anyways

neon sable
#

ggs i have a headache im done for today ty anyway

solar hill
#

also dont crosspost

stuck parrot
#

hey i got an issue with 2d top down mechanics. I got a script where I can move the character right, left, up and down. but if I press W and S or A and D at the same time, the movement cancels eachother out (-1 + 1 = 0) is there a common fix for that? heres the script if it helps ```using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerMovement : MonoBehaviour
{
GameControls input;

public float walkSpeed = 5f;
private Rigidbody2D rb;
private Vector2 moveValue;

private void Awake()
{
    input = new GameControls();
    rb = GetComponent<Rigidbody2D>();
}

public void Update()
{
    moveValue = input.Player.Move.ReadValue<Vector2>();
}

private void FixedUpdate()
{
    // Physics movement
    rb.linearVelocity = moveValue.normalized * walkSpeed;
}

private void OnEnable()
{
    input.Player.Enable();
}
private void OnDisable()
{
    input.Player.Disable();
}

}```

keen dew
#

What do you want to happen instead?

stuck parrot
rose kernel
#

is this 3d?

stuck parrot
rose kernel
solar hill
#

you keep manual track of the button presses and store the latest one

stuck parrot
naive pawn
#

"polling" is continuously requesting the state, like you're doing here

naive pawn
#

a callback would be registering an action for the inputsystem to call when something happens (in this case, when the input value changes)

solar hill
#
// add a direction to a list when you press a key, remove on release
input.Player.Move.performed += ctx => moveStack.Add(ctx.ReadValue<Vector2>());
input.Player.Move.canceled += ctx => moveStack.Remove(ctx.ReadValue<Vector2>());

// you then move towards the very last item added to that list
Vector2 moveDir = moveStack.Count > 0 ? moveStack[^1] : Vector2.zero;
#

i stole this from a forum post but it illustrates it nicely

stuck parrot
# solar hill Here 👆

is ctx a thing or is it something you just named yourself? also dont know what += and => does (:

solar hill
#

ctx stands for context

#

its generally used for objects that provide some kind of methods to pass data or trigger actions

solar hill
stuck parrot
solar hill
#

youre close but not really lol

#

same general concept but we arent using ctx to just store the vector2 value

#

ctx is an object

#

it can contain more information than just the vector2 value

vernal salmon
#
    {
        if (isOpen)
        {
            t += Time.deltaTime * rotateSpeed;
            t = Mathf.Clamp01(t);
            transform.rotation = Quaternion.Slerp(closeRot, openRot, t);
        }
        else
        {
            t += Time.deltaTime * rotateSpeed;
            t = Mathf.Clamp01(t);
            transform.rotation = Quaternion.Slerp(openRot, closeRot, t);
        }
    }```
I've got this door script, I believe it should work but for some reason it has been glitching out. When I change the bool it waits a bit and only when t = 1 does it go to the rotation. the slerping is not happening. openRot and closeRot btw are both quaternions and t is just a float and I can see its actually going from 0-1 properly.
stuck parrot
#

My brain does the windows error sound when i see += . does it mean that t stores Time.deltaTime * rotateSpeed in addition to whats already assigned to t? also isnt "t = Mathf.Clamp01(t);" just overwriting t to thatever Mathf.Clamp01 means?

polar acorn
wintry quarry
vernal salmon
#

In the inspector t is working as expected

vernal salmon
#

I made it a custom variable

wintry quarry
polar acorn
solar hill
wintry quarry
#

in this case it's just a simple x = x + y written as x += y

solar hill
#

oh praetor

#

i was talking about the earlier one

#

i posted lol

wintry quarry
#

oh sorry

solar hill
#

i thought this was what nuke was refering to

vernal salmon
#

I'll send it soon. But I just have an open door function which changes the bool and sets t to 0 and checks if it's locked and a function for opening a locked door

wintry quarry
#

He seems to be talking about t += Time.deltaTime * rotateSpeed;

solar hill
vernal salmon
#

I could also send the code for how the openDoor is called

solar hill
#

!code

radiant voidBOT
solar hill
#

please use the paste sites for larger blocks of code

vernal salmon
#

sorry

umbral bough
#

Hey, I am very confused with how I should update this:

return Object.FindObjectsByType<T>(FindObjectsInactive.Include, FindObjectsSortMode.None);

I keep getting a warning in Untiy 6.5:

/home/nn/Data/Projects/Unity/Katana/Modules/UnityUIEffect/Packages/src/Runtime/Internal/Utilities/Misc.cs(24,77): warning CS0618: 'FindObjectsSortMode' is obsolete: 'FindObjectsSortMode has been deprecated. Use the FindObjectsByType overloads that do not take a FindObjectsSortMode parameter.'

And the wiki doesn't really offer an alternative for sorting, so what do I do?
https://docs.unity3d.com/6000.5/Documentation/ScriptReference/Object.FindObjectsByType.html

wintry quarry
umbral bough
#

so sort mode none is the default behavior now?

wintry quarry
#

I guess? This is a new deprecation - and a surprising one to me

#

Haven't run into it personally, but they only recently introduced that stuff so it's surprising they're deprecating it

umbral bough
#

yeah

#

thanks

polar acorn
vernal salmon
#

yea

#

for closed it snaps immediately at 0 though

#

which is also weird

polar acorn
#

Just as a sanity check, I'd say change the contents of those conditions to just transform.rotation = openRot and the same for closeRot. Does it snap into the orientations you expect instantaneously?

vernal salmon
#

yes

rancid nova
#

Hello I need help with making my isometric tile palette fit in its diamond shape

#

Hello I need help with making my isometric tile palette fit in its diamond shape
Im not sure why it does this ive been stuck on this for a while, i've followed official docs and i just cant seem to get itright

#

Im thinking maybe its caused by the actual sprite img sizes?

rich adder
#

most likely issue with PPU

rancid nova
#

Understood

#

ty

vernal salmon
#

I moved the slerp to a variable and debug.log it and the quaternion is indeed changing

#

and if I try to adjust in the inspector the rotation it does not let me

polar acorn
# vernal salmon yes

Okay, now put the slerps back, but hard-code in t as 1 instead. Does it do the same thing?

vernal salmon
#

changing from slerp to lerp gave this error
Assertion failed on expression: '!CompareApproximately(aScalar, 0.0F)'
UnityEngine.Quaternion:Internal_Lerp (UnityEngine.Quaternion&,UnityEngine.Quaternion&,single)
Door:Update () (at Assets/Door.cs:52)

polar acorn
vernal salmon
#

they're quaternions in the inspector I had to input the values as euler though

#

so openRot is 0, 0, 0 and closeRot is 0, 90, 0

rich adder
polar acorn
#

So, at some point along the slerp, it's making a malformed Quaternion?

It might be easier to see if you make openRot and closeRot explicitly into Vector3s, then do Quaternion.Euler(openRot) and such instead? That way it might at least tell you what the problem child is

vernal salmon
polar acorn
rich adder
#

oh huh thats interesting

polar acorn
#

Yeah, I didn't know that either. I had to go check.

#

It might be doing something fucky under the hood though, so I think explicitly setting euler angles and converting them later might help?

vernal salmon
#

it works kinda

#

it overshoots when closing though

swift crag
#

I bet your openRot is malformed

#

Set it to some other value, then set it back to zero

#

Do not hit undo

#

The default value for a Quaternion is all-zeroes (because it's a struct)

vernal salmon
#

nope

swift crag
vernal salmon
#

I even reset the script

swift crag
#

resetting the component will not help

vernal salmon
#

I set all the values to a random number and then swtched back to 0

swift crag
vernal salmon
#

Btw I'm trying the vector3 approach digiholic suggested

stuck parrot
#

can anyone explain input.Player.Move.performed += ctx => moveStack.Add(ctx.ReadValue<Vector2>()); because im totally lost here to understand what += is (and the fact that its a subscription is not helping me) what is it subscribing to? what is ctx, a value, a variable? and the rest of the block is also not making sence. I tried let chatGPT explain it to me but even the explainations there are too hard for me to understand.

swift crag
#

You can split this into two lines to make it a bit easier to grok

#

=> is used to declare an anonymous function

#

it's like a method (e.g. Awake, Update, etc.), except that it doesn't have a name

#

it's just an object

#

ctx => ...

This is an anonymous function that accepts one argument.

#

The argument is named ctx

#

you could rewrite this at:

private void HandleMove(InputAction.CallbackContext ctx) {
  moveStack.Add(ctx.ReadValue<Vector2>());
}

void Start() {
  input.Player.Move.performed += HandleMove;
}
#

In fact, you should probably do this!

#

You can never un-subscribe from the performed event if you use an anonymous function like that

#

you need to un-subscribe with the exact object you subscribed with

rich adder
#

bleh anonymous functions, they always feel so dirty to use
btw they named itctxbut can be anything you chose, its just here short for context

swift crag
#

the last one had the values changed

polar acorn
#

They're fine when you're doing something like a Linq query where they're just gonna disappear, but for subscribing you shouldn't use em, so you can remove em later

swift crag
#

i'm slerping from a quaternion to Quaternion.identity

#

I use static anonymous functions along with RefLinq quite a bit

#

static forbids you from capturing anything, which causes an allocation

wintry quarry
swift crag
wintry quarry
#

WHich is just a shortand way of writing a function

#

ctx => moveStack.Add(ctx.ReadValue<Vector2>()); is shorthand for:

void MyFunction(CallbackContext ctx) {{
  moveStack.Add(ctx.ReadValue<Vector2>());
}```
#

So that function will run whenever you move your joystick after you do the += thing

rich adder
swift crag
#

I use them whenever I need to do a certain thing once

#

meaning that there is no sense in writing a reusable method

stuck parrot
swift crag
#

notably, you can also turn a method into an object that you can pass around

vernal salmon
swift crag
#

void Hello() {
  Debug.Log("Hello");
}

System.Action foo = () => Debug.Log("Hello");
System.Action bar = Hello;
swift crag
#

You probably just meant to do Quaternion.Euler

vernal salmon
#

even euler did the same thing

rich adder
vernal salmon
#

and whenever I use quaternion it does the snap issue

swift crag
vernal salmon
#

well in the new code with the vector3 it goes to the rotation and overshoots

#

and other values get it completely wrong

swift crag
#

you're setting transform.rotation, rather than transform.localRotation, which is suspicious to me

#

this means that you're setting your world-space rotation, rather than your rotation relative to your parent

#

that wouldn't cause the snapping

#

but it would cause the door to appear to rotate in nonsensical ways

vernal salmon
#

It is in the world space the door

#

Like the door script is on an object with no parents

#

Should I make it local rotation

#

I'd have to try tmrw thougj

swift crag
#

It would be more correct, IMO

#

But it's not the cause of your problem here

vernal salmon
#

It's weird cos this is the same way I've always done doors and rotations

swift crag
#

It is weird, yes. Everything you're doing looks fine to me

#

At this point, I would try making a new door (well, just a cube with the Door component on it) and seeing if it behaves right

naive pawn
#

i don't have full context, but just a quick check - have you checked for animators (or other components) on that object, that might be controlling the transform?

swift crag
#

That's my thought, yeah

#

external interference!

#

It'd also be helpful to see a recording of what's happening

#

If the door is eventually rotating, then I doubt something else is controlling it

#

(this kind of thing is usually all-or-nothing)

charred drift
#

Hello, so I am trying to figure out the simplest of concepts (animator transitions) but I am struggling way too much.
How my system works is simple, I use an animator manager that plays an animation with CrossFade() and jumps to the specific animator states (in this case Block Hit and Block Start) and then they transition all the way to an Empty state which just has a script that resets some combat flags.
The input for blocking (which is RMB) is directly controlling the animator bool flag isBlocking (so it is unrelated to the combat manager isBlocking flag).
My issue is that for some reason my Block Hit animator state and Block Loop do not want to cooperate. The bug happens when i block a hit and then stop blocking immediately after, which causes the Block Hit state to be playing even after transition and Block Loop does not exit through the transition to Block End even when the condition is met and has no Exit Time.
Can someone explain what is happening because this makes 0 sense to me?

vernal salmon
naive pawn
bright hill
#

idunno this is animator problem or most likely coding problem. i have short weapon fire animation which length is 1 second. in game its looping for... 2-3 seconds?

here is my code and video

public void HandleShoot()
{
muzzleFlash.Play();
currentAmmo--;
Debug.Log(gunData.weaponName + currentAmmo + "/" + gunData.magSize);
gunAnims.SetBool("Fire1", true);
Shoot();
Invoke(nameof(PlayFireAnim), 1f);

    controller.ApplyRecoilCam(gunData);
}

//shit i need to make timer without courutine cuz i think it will break my code
void PlayFireAnim()
{
    gunAnims.SetBool("Fire1", false);
}
charred drift
verbal dome
verbal dome
#

A trigger is just a bool that turns to false immediately when it is "used"

verbal dome
#

Also FYI the animation you are showing is 0.1 seconds, not 1 second

#

That's why it plays multiple times in one second while the bool is true

#

But yeah use trigger

bright hill
#

i didn't sleep this night and i started learning animator stuff hehe

verbal dome
#

Make sure to remove the condition in the transition from fire->idle so it happens automatically

#

(If it already doesn't get removed when you change to trigger)

verbal dome
#

Because they might not fire always when a fade is happening, IIRC

charred drift
# verbal dome Are you depending on animation events for some transitions?

I do have a custom animation event system which handles that with no issue, but my problem is with the transitions from Block Hit to Block Loop.
I've tested it without the events and it still does the same thing. What solved it was making the crossfade duration lower than the duration of the transition from Block Hit to Block Loop.

hot hamlet
#

can someone tell me why using this.gameObject in the script gives the error "object reference not set to an instance of an object". when i look at the script, "this" is slightly dimmed out, making me think that its the problem. i have it in fixedUpdate

wintry quarry
#

"this" is slightly dimmed out, making me think that its the problem
That's definitely not the problem. It's dimmed out hbecause it's unnecessary

#

you could have just written gameObject instead of this.gameObject

hot hamlet
#

public class PlayerController : MonoBehaviour
{
private GameObject player;
player = gameObject;
void FixedUpdate()
{
if (isDrowning == true)
{
Movement(false, false);
isDrowning = false;
PlayAnimation.Drown(player); //error here
}
}

wintry quarry
#

That is PlayAnimation.Drown(player); not this.gameObject causing the error

#

Does this code even compile?

#

None of this should compile

#

player = gameObject; should be an error because you can't access non static variables outside a method
and:
PlayAnimation.Drown(player); //error here you're using a variable that doesn't exist here called PlayAnimation

verbal dome
#

And Movement(), and isDrowning...

#

Just show the actual code

wintry quarry
#

This looks like this is not the full code

hot hamlet
#

ok my bad give me one sec to show you what i had because i accidently removed something

wintry quarry
#

!code

radiant voidBOT
hot hamlet
#

yes its my bad....

#

im sending

#
{

    private Animator animator;
    public bool isDrowning = false;
    public bool allowedToMove = true; //only for movement
    public bool allowedToControl = true; //for movement and everything else like item usage
    private AnimationPlayer PlayAnimation;
    public GameObject player;
    void Start()
    {
        spriteRenderer = GetComponent<SpriteRenderer>();
        animator = GetComponent<Animator>();
    }
    void Update()
    {
           
    }
    void FixedUpdate()
    {
        currentPosition = transform.position;
        movementDirection = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
        if (allowedToMove == true)
        {
            transform.position = new Vector2(currentPosition.x + movementSpeed * Time.fixedDeltaTime * movementDirection.x, currentPosition.y + movementSpeed * Time.fixedDeltaTime * movementDirection.y);
        }
        
        if (isDrowning == true) //when we impliment water detection, just put this there
        {
            Movement(false, false);
            isDrowning = false;
            PlayAnimation.Drown(gameObject); //error here -----------------
        }

        animator.SetFloat("horizontalInput", movementDirection.x);
        animator.SetFloat("verticalInput", movementDirection.y);
        if (animator.GetCurrentAnimatorStateInfo(0).IsName("RunRight") || animator.GetCurrentAnimatorStateInfo(0).IsName("IdleRight")) //only until we get right facing animation
        {
            spriteRenderer.flipX = true;
        }
        else
        {
            spriteRenderer.flipX = false;
        }
    }
    void DrowningAnimationFinished()
    {
        PlayAnimation.RespawnAnimation(gameObject);
    }
    public void Movement(bool allowMove, bool allowControl)
    {
        allowedToMove = allowMove == true ? true : false;
        allowedToControl = allowControl == true ? true : false;
    }
}
wintry quarry
hot hamlet
#

i removed some variables outside of the problem because of character limits here

#

AnimationPlayer.cs

public class AnimationPlayer
{
    void Start()
    {

    }
    void Update()
    {
        
    }
    public void Drown(GameObject player)
    {
        Animator animator = player.GetComponent<Animator>();
        animator.Play("Drown");
    }
    void Push()
    {

    }
    public IEnumerator RespawnAnimation(GameObject player)
    {
        SpriteRenderer spriteRenderer = player.GetComponent<SpriteRenderer>();
        float drowningDelay = 0.75f;
        spriteRenderer.color = Color.clear;
        yield return new WaitForSeconds(drowningDelay);
        spriteRenderer.color = Color.white;
        player.GetComponent<PlayerController>().Movement(true, true);
    }
}
#

i just marked it

#

im sorry guys im new to this so mb for being difficult

wintry quarry
hot hamlet
#

oh

wintry quarry
#

You never assigned it

#

and it's private so it's certainly not being assigned in the inspector

hot hamlet
#

do i have to do PlayAnimation name = new PlayAnimation();

wintry quarry
#

No, it's a MonoBehaviour

#

you need to assign it to the actual one you want to reference

#

make it public and assign it in the inspector - that's the simplest way

hot hamlet
#

im sorry i dont really understand.
i put this
public AnimationPlayer PlayAnimation;
set it to public but it doesnt show in inspector

#

if its not obv im a beginner so im a lil lost

verbal dome
#

Oh, and importantly, AnimationPlayer needs the [Serializable] attribute

wintry quarry
#

er

verbal dome
#

Otherwise it won't be shown in the inspector (or saved)

wintry quarry
#

it's confusing because that script has Start and Update but it's not a MonoBehaviour

#

so it's not clear to me if this is supposed to be a MonoBeahviour or not

verbal dome
#

Yeah, maybe they made it with thet mono template and removed : MonoBehaviour...?

wintry quarry
#

I actually assumed it was above when I said not to use new()

#

if it's supposed to be a plain C# object then yes you can use new() to instantiate it

hot hamlet
#

this is the only error i get when i turn on isDrowning in the inpspector

wintry quarry
#

but I would remove Update and Start from it to avoid confusion

hot hamlet
#

just removed them

wintry quarry
#

well either that - or you create it manually with new()

hot hamlet
#

[Serializable] public AnimationPlayer PlayAnimation;
Attribute is not valid on this declaration type. It is only valid on specific declarations. (the [Serializable] has the red line]

wintry quarry
verbal dome
#

Is AnimationPlayer something you want to edit in the inspector?'

wintry quarry
#

there doesn't seem to be anything on it to edit

#

it's just a couple of public methods

hot hamlet
#

it would definetly be convinient later on lol

wintry quarry
#

if you want to make the animation values configurable it might makje sense

hot hamlet
#

[Serializable]
public class AnimationPlayer
this worked atwhatcost

#

and i think i understand why

#

so i appreciate all the help

umbral bough
#

Hey, I am porting some older code to unity 6.5, and can't figure out whether I should explicitly use the ToULong, or whether the implicit ToString already does that in the background?
https://docs.unity3d.com/6000.5/Documentation/ScriptReference/EntityId.ToString.html

#if UNITY_6000_5_OR_NEWER
                    _foldouts[group.Key] = new SavedBool($"{EntityId.ToULong(target.GetEntityId())}.{group.Key}", false);
#else
                    _foldouts[group.Key] = new SavedBool($"{target.GetInstanceID()}.{group.Key}", false);
#endif

Please @ me and thanks in advance!

naive pawn
#

but if you want to be sure, just use the explicit ToULong. ToString could be user-facing and come with more info

umbral bough
#

thanks!

naive pawn
#

granted it could be extern'd, but won't know until you check

verbal dome
naive pawn
#

UnityCsReference is at 6.2.0b4 right now lmao

umbral bough
# verbal dome Just curious, why do you choose to use that (for unity dev)?

Started with vs, switched to rider, switched to linux, switched to zed, and now finally switched no nvim.
I can just use it anywhere, even when I ssh into my server, it's just way more convenient to configure one thing correctly and use it everywhere than have 5 different tools that do the same job.
On top of that, rider's "free" license is not exactly free, you can't be making money iirc.
And prob the main reason, I just like nvim binds ig(none of the integrations besides zed are anywhere close to the real thing).

#

Zed does have the remote thing, but that opens a whole new zed window instead of just staying in the terminal, and not to mention devs refusing to merge in half the features that have been open for 3+ years, but besides that, it was a decent editor for a while.

#

And prob one last thing that might explain why I like minimal editors, I just don't like all the popups etc. that get in your way.
I have autocompletions set up to appear when I press ctrl+space, but I hate them constantly being there.
Ik you can do this in other ides too, I just found it to be easier here.

naive pawn
#

fwiw vscode has a "vim mode" (and "emacs mode"), i'd hazard a guess other ides have them too. not saying to switch, just mentioning that in case it might make your life easier if you do have to use others lol

umbral bough
naive pawn
#

ah well i can't find it now that i mention it lol. mightve been in like, monaco or something.

ruby timber
#

idk if the fact that it can fall is normal (player movement)

naive pawn
#

oh they're extensions. i was remembering "vim mode" from coc's embedded monaco lmao...

waxen adder
#

Let's say I got an effect class. I'm trying to think how I would neatly introduce the concept of effect durations and the associated duration types (instant, seconds, infinite, etc.). Should I introduce this stuff within the effect class itself, or extend out into child classes for this?

using UnityEngine;

public abstract class Effect : ScriptableObject
{
    public abstract void OnApply(EffectContext context);
}
naive pawn
ruby timber
#

and if I dont want it to fall how do I make it so it doesnt

naive pawn
#

are you referring to falling down or falling over?

ruby timber
#

fallingg over

naive pawn
#

constrain x and z rotation on the rigidbody

ruby timber
#

so in the fixedupdate I just put its x and z rotation to 0?

naive pawn
#

no, there's a section called constraints on the rigidbody component

ruby timber
#

ohhh

#

thanks for telling me about this lol

naive pawn
# waxen adder Let's say I got an effect class. I'm trying to think how I would neatly introduc...

consider drawing out (on paper, on a whiteboard, in notepad, etc) the relation between this class and its users, how they interact and such
see what you need as the API for this object, see how that fits in with making conditionals vs making subclasses

ik that's pretty vague advice but it'll really depend quite a bit on what it needs to do and how you want to do it (eg where might branching decisions be?)

ruby timber
#

how do I make the mouse cursor not visible like in most first person games? solved

umbral bough
finite flower
#

How would I make a variable change on a curve?
Like a certain stat that grows less the more it levels, for example: Level 1 adds 5 points, level 2 adds 4 points, level 3 adds 3 points, etc

teal viper
#

Or a lookup table. Might be more suitable for integers that you want to author yourself.

finite flower
teal viper
#

Then look into unity animation curves. You can then floor/ceil/round the number to an integer.

bleak hull
#

i tried learning a few months ago but i kind of just stopped doing it, thinking about starting again

#

really want to do it but its so complicated lol

#

i get a proper setup in a week or 2 so thats nice

#

should i try the tutorial template thingies?

ivory bobcat
naive pawn
grim vine
#

Hello✌️

#

Does anybody know to make a 3d shop

frosty hound
#

What an impossibly vague question

#

What part of a "3d Shop" are you having trouble with coding?

#

And the answer can't be "all of it because I didn't try"

umbral bough
#

thanks for confirming tho

muted sand
#

I am using a delta pointer, if I position my mouse off center of my game when i start it, why does the camera instantly snap to that position but on the second frame?
Shouldn't that be perceived as no change since that was the position of the mouse when I started the game?

using Unity.Mathematics;
using UnityEngine;
using UnityEngine.InputSystem;

public class CameraController : MonoBehaviour
{

    [SerializeField] Camera Camera;
    [SerializeField] CursorLockMode CursorLockMode;
    [SerializeField] float MinimumPitch;
    [SerializeField] float MaximumPitch;
    [SerializeField] float MinimumYaw;
    [SerializeField] float MaximumYaw;
    [SerializeField] float Sensitivity;

    private Vector2 current_mouse_xy;
    private float total_pitch;
    private float total_yaw;

    void Start()
    {
        Cursor.lockState = CursorLockMode; // Locked, Confined, None
    }

    void Update()
    {
        total_pitch -= current_mouse_xy.y * Sensitivity;
        total_yaw += current_mouse_xy.x * Sensitivity;

        total_pitch = (MinimumPitch == MaximumPitch) && (MinimumPitch == 0) ? total_pitch : math.clamp(total_pitch, MinimumPitch, MaximumPitch);
        total_yaw = (MinimumYaw == MaximumYaw) && (MinimumYaw == 0) ? total_yaw : math.clamp(total_yaw, MinimumYaw, MaximumYaw);
        
        transform.localRotation = Quaternion.Euler(total_pitch, total_yaw, 0);
    }


    public void OnCameraLook(InputAction.CallbackContext mouse_input) => current_mouse_xy = mouse_input.ReadValue<Vector2>();
}
muted sand
wintry quarry
hoary heath
#

Hey guys, i'm having a stroke I think xD

I'm trying to make a 2D rectangle where I can change each pixels individually with code for testing some functions of procedural generation before going 3D.

It seems I can't find any tutorials that explain how to handle pixels indivisually, and i'm sure i've seen some tutorials a couple years ealiers so I know those exists....

sour fulcrum
#

a texture?

hoary heath
#

Damn i was looking at image and canvas and not texures... that was the issue

#

thanks

queen adder
#

anyone wanna see if my playfab login is secure or not it was taken from youtube and changed up

worn niche
#

Hi, when I build my project my FPS are even worse than in the editor. Somehow the cams are using nearly everything. Also LogStringToConsol takes a huge piece of that, But I checked every script in the scene and non of that is calling Debug.Log repeatedly. What could cause this?

sour fulcrum
#

whats calling logscenetoconsole?

worn niche
teal viper
#

Take a screenshot of the whole profiler window.

worn niche
teal viper
#

And avoid relying on percentages. Rely on cpu time.

worn niche
teal viper
#

Sorted by (cpu) time

worn niche
#

so like that

teal viper
# worn niche so like that

Yes.
So a few things to clear up:

  • you're getting stable 60 fps(aside from a few spikes).
  • it seems like you have 2 cameras rendering a lot of objects.

You don't need to expand all the way down. It's enough to go down to 5ms split and maybe one call deeper.

worn niche
sour fulcrum
#

what resolution are you running the editor game view at?

teal viper
worn niche
worn niche
toxic cloak
teal viper
magic magnet
#

so i just download the unity hub but when it downloads the editor at 100% it says validating then faild to download i tried three times but still the same

queen vale
magic magnet
toxic cloak
queen vale
toxic cloak
#

owk thanks

tight fossil
#

the rect transform of a UI object is being set to -9720 making it not display on screen and i can't seem to set it to 0 even with Vector2s or a Vector3 with a 0 at the end.
Only way I can stop it is changing transform.position to localPosition but then the box does not align with the mouse position

    {
        //transform.localPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        transform.position = Input.mousePosition;
    }

    public void SetAndShowTooltip(string message)
    {
        gameObject.SetActive(true);
        textComponent.text = message;
        Cursor.visible = false;

        gameObject.GetComponent<RectTransform>().pivot = new Vector2(0, 1);
    }```
#

Orthographic camera, Canvas render mode set to screen space camera

sour fulcrum
#

You might need to use RectTransform anchoredPosition?

magic magnet
tight fossil
queen vale
tight fossil
#

middle center

queen vale
#

wouldnt that be 0.5, 0.5

tight fossil
#

I believe so

#

ah

#

I see 😂

queen vale
tight fossil
#

thanks!

queen vale
#

Batby, you got any ideas?

queen vale
queen vale
fair cedar
#

how to input code in a block?

#

nvm

sour fulcrum
fair cedar
#
        if (canTurbo)
        {
            if (Input.GetKey(KeyCode.Space))
            {
                playerRb.AddForce(focalPoint.transform.forward * turboStrength * Time.deltaTime, ForceMode.Impulse);
                canTurbo = false;
                GameObject TurboParticle = Instantiate(turboParticlePrefab, transform.position, turboParticlePrefab.transform.rotation) as GameObject;
                StartCoroutine(TurboCooldown());
            }
        }


    }

    IEnumerator TurboCooldown()
    {
        yield return new WaitForSeconds(turboCooldown);
        Destroy(turboParticle);
        canTurbo = true;
    }
#

why does the instantiated object does not destroy() ?

sour fulcrum
#

what is turboParticle

fair cedar
#

oh i think i found it i am stupid

sour fulcrum
#

😛

fair cedar
#

oh nvm still doesnt destroy()

queen vale
# sour fulcrum 😛

probably wrong but doesn't a coroutine need to return something?
yield return new waitforseconds(0.5f); kinda thing at the end?

fair cedar
#

turboCooldown is a variable

#

doesn't it do the same?

sour fulcrum
#

your code has TurboParticle and turboParticle variables

#

these are not the same

fair cedar
#

i changed it already

sour fulcrum
#

you need to post up to date code for up to date advice 😛

fair cedar
queen vale
#

don't quote me but, I would do it as:

    IEnumerator TurboCooldown()
    {
        while(activeInHierachy)
      {
        Destroy(turboParticle);
        canTurbo = true;
        yield return new WaitForSeconds(turboCooldown);
      }
    }
#

: |

#

: | what'd i do this time

sour fulcrum
#

fixing a problem that doesn't exist

#

their coroutine code is fine

fair cedar
#
            if (Input.GetKey(KeyCode.Space))
            {
                playerRb.AddForce(focalPoint.transform.forward * turboStrength * Time.deltaTime, ForceMode.Impulse);
                canTurbo = false;
                GameObject turboParticle = Instantiate(turboParticlePrefab, transform.position, turboParticlePrefab.transform.rotation) as GameObject;
                StartCoroutine(TurboCooldown());
            }
        }


    }

    IEnumerator TurboCooldown()
    {
        yield return new WaitForSeconds(turboCooldown);
        Destroy(turboParticle);
        canTurbo = true;
    }
#

this still doesnt work

queen vale
#

so their routine is fine, but what about return at the first line of it running?

sour fulcrum
#

also fine

queen vale
#

: o oh

sour fulcrum
# fair cedar ```cs if (Input.GetKey(KeyCode.Space)) { ...

correct, because of the GameObject type deceleration in the top code, that's a local variable to that function.

turboParticle and turboParticle are still different things here (confusing i know)

You can just do turboParticle = Instantiate(turboParticlePrefab, transform.position, turboParticlePrefab.transform.rotation);

queen vale
#

So this is a scope issue(?)

magic magnet
# queen vale Without further information, I'd look to [this](https://discussions.unity.com/t/...

it says its cuz he didnt respond to UAC popup but i did everytime but it still says download also in the install help documentation they said check the logs or install in different disk i couldnt find anything in logs but installing it in different disk gives the same error and one of the guy says it happenes in newer version old one downloads fine now how do i select which version i want to download

fair cedar
#

so i just create the variable at the top so that it is public?

#

GameObject

sour fulcrum
#

doesn't need to be public, private would be fine. is your code not erroring and giving you red lines right now?

fair cedar
#

or can i assign arguments to the Ienumerator

sour fulcrum
#

this should be invalid code if you don't already have a turboParticle variable declared in that class

    IEnumerator TurboCooldown()
    {
        yield return new WaitForSeconds(turboCooldown);
        Destroy(turboParticle);
        canTurbo = true;
    }
fair cedar
#

or do you mean Ienumerator

sour fulcrum
#

can you post the whole script

#

!code

radiant voidBOT
queen vale
#

is the coroutine ever started?

#

StartCoroutine(TurboCooldown()); - vs - StartCoroutine(TurboCooldown);

fair cedar
#

thank you i fixed it

queen vale
#

not again ; - ; - nvm. I'm not answering anything without an IDE open lol

fair cedar
#
    IEnumerator TurboCooldown()
    {
        GameObject turboParticle = Instantiate(turboParticlePrefab, transform.position, turboParticlePrefab.transform.rotation) as GameObject;
        yield return new WaitForSeconds(turboCooldown);
        Destroy(turboParticle);
        canTurbo = true;
    }
#

is this good practice? or should i use arguments or public stuff

sour fulcrum
#

that's fine as a solution in isolation but it's not ideal that you don't know what was happening before (no judgement it's just a pretty core thing)

fair cedar
#

yeah i just forgot that it was in a differnet scope

tame juniper
#

really simple one but does anyone know how to put text on a prefab like not with the canvas?? if that makes sense like its a child of the parent prefab i guess and moves with it

sour fulcrum
#

world space canvas

#

either on the prefab itself or on the gameobject parent the prefab spawns under

strong wren
tame juniper
#

thanks!

tame juniper
keen dew
tame juniper
#

oh

#

makes sense

worn niche
wintry quarry
worn niche
#

I forgot to mention that all lights are baked

worn niche
teal viper
# worn niche sure, I would appreciate it. So I removed the mirror for now and I found out tha...

The spike is likely something like shader or PSO compilation - something that happens once the first time the shader is used(there are ways around it, but it's a whole different story).

As for fps, as a gamedev you should start thinking in frame time(in ms) rather than fps. 100 fps is like 10 ms frames, while 200 is 5ms. 60 fps is 16.6 ms, so 60 to 100 is almost the same difference in time as between 100 and 200 fps.
And then there are optimizations.

worn niche
#

forgot to mention that too 😅

teal viper
worn niche
teal viper
dense totem
#

Yo guys, what's up? I'm kinda new to programming and I'm having some trouble to construct my PlayerController class. I've used Claude to act like an instructor to me, so we constructed the system based on events, it works, but I'm feeling like I'm losing control of the system. What do you recommend? Keep trying to fix or start again with other architecture? the projetc until now: https://github.com/magopoligonal/Unity/tree/CombatSystem/Aprendizados/Assets/Scripts

GitHub

Basico. Contribute to magopoligonal/Unity development by creating an account on GitHub.

wintry quarry
# dense totem Yo guys, what's up? I'm kinda new to programming and I'm having some trouble to ...

Do you have a specific question here?

My recommendation is to not use any code Claude produces until you understand what it's doing. Otherwise you will absolutely "lose control" of it. It's a powerful tool but not super useful if you don't understand what it's doing.

Anyway this is just vague and nobody (other than an ai tool) is going to spend a lot of time looking over a whole project and making general recommendations without a specific question

dense totem
#

Yeah, that's make sense, sorry for that haha. My main question is if it's okay work with events to pass and control data, it looks uncoupled but at the same time it's hard to control priority. For example, I'm having trouble to make a combo system. I've fixed a lot of things, but my transition between Attack02 to Attack03 is broken. It's like they can pass trough the coroutine without respecting the time window that I put on the animation event.

wintry quarry
slim solar
#

Can anyone tell me why my VS turned into all these whacky colors over night?

dense totem
#

I'm still not a OOP guy (started with C ), you recommend to use interface and stuff? I've seen some tutorials on that I think but it feels scary at the first glance ;-

slim solar
#

It used to be the normal colors of light blue/cyan stuff. Why all this red/orange?

wintry quarry
wintry quarry
#

AFAIK I you can customize the colors and the old theme probably still exists somewhere

slim solar
#

Wait so they updated the software and changed all the colors from what they were for the last 10 years?

#

Is this for real

wintry quarry
#

Like I said I don't use Visual Studio, so I don't know. Just basing this off what I've seen in this discord casually over the last few days

wintry quarry
slim solar
muted sand
wintry quarry
muted sand
wintry quarry
# muted sand the frames the mouse is being locked

the code would be pretty simple.
E.g.:

bool ignoreMouseDelta;

void LockCursor() {
  Cursor.lockState = CursorLockMode;
  ignoreMouseDelta = true;
}

public void OnCameraLook(InputAction.CallbackContext mouse_input) {
  if (ignoreMouseDelta) {
    current_mouse_xy = Vector2.zero;
    ignoreMouseDelta = false;
  }
  else {
     current_mouse_xy = mouse_input.ReadValue<Vector2>();
  }
}```
wintry quarry
#

by the way

#

the way you're handling OnCameraLook isn't ideal anyway

#

It actually looks really buggy

#

Pretty sure OnCameraLook is only going to run when the mouse is actually moving

#

Are you actually getting calls to OnCameraLook when the input is zero?

#

If not this code is just going to keep spinning you forever

manic vector
#

I'm trying to make a game where everything thats within a 360 degree view of the player is frozen in time.

I think i have an approach to work out whether an object is in view, but I thought I'd check in case its impossible/stupid. The big constraint is that if just one pixel of the object is on screen, it should be frozen.

My approach is this:
Write a shader that makes the color of each pixel the objectID it hits
Render a cubemap from the playercamera with that shader with a pretty low resolution, then iterate over the pixels, and say the object should be frozen that frame if it's in there

Any advice?

sour fulcrum
#

i don't get how these two statements don't conflict

polar acorn
#

A "360 degree view" is, like, everywhere

manic vector
#

Oh i mean like, if you consider the "screen" to be that 360 degree view

manic vector
polar acorn
#

Sounds like the easiest way to do this is to use the OnBecameVisible... yeah that

#

🐢

manic vector
#

My understanding was that unity's occlusion culling would be too approximate - I need like, super consistent behaviour otherwise it'll feel cheap.
If I'm wrong and its super exact though, I'll use that

sour fulcrum
#

i don't think any solution is gonna be perfect for you off the bat

#

maybe you'll need a little timer or something aswell idk

#

you'll have to play around abit

#

def. probably not that pixel shader route

manic vector
#

Thats just too slow I'm guessing? From iterating over a ton of pixels on the cpu every frame

sour fulcrum
#

too slow and probably not a very accurate way either tbh

#

either those camera functions or manual raycasting / physics related stuff is probably your route

manic vector
#

Do you know if OnBecameVisible is gonna be inaccurate on only one side? Eg. if its actually visible, its visible all the time according to that function, or is it that if its invisible according to the function, its actually invisible all the time. Because i could use that to chop down the things to check a little

night raptor
sour fulcrum
manic vector
oak marlin
#

I don't know if this is the right place but... I have been wanting to make a video game but programming in C# is the only thing standing in my way. I have been using Unity for about 4 months now (following tutorials) but whenever I try to make my own game stuff falls apart until I inevitably delete the project. Where can I go to learn all the physics and C# related stuff so I can actually code my games?

solar hill
#

also

#

!learn

radiant voidBOT
manic vector
# sour fulcrum i dont know what you mean by this

Visual aid because I'm bad at explaining things.
If you imagine whether you are in view or not is on that scale.
The black scale is the truth of whether you are in view, if you are to the left of the bar, you arent in view, and if you are on the right, you are in view.
The red scales are possibilities for what unity could be telling me - In the top case for example, if you are past the red bar, you know for a fact that the player can see it, but if you are to the left of it, it could be that you cant see it, but unity says you can.

Like a "A implies B, but B does not imply A", but in this case its "Unity says object became visible => object is actually visible, but object is actually visible =/> unity says object became visible"
It could of course be neither, and its just completely approximate

sour fulcrum
#

the two unity calls are consistent in how they are ran

#

they are either consistently "wrong" or "right" depending on what you want out of them

manic vector
#

Also, if im not mistaken, occlusion maps are baked? So using OnBecameVisible wouldn't work with using objects to block view of other objects

sour fulcrum
#

these calls are not related to occlusion culling afaik

manic vector
night raptor
# manic vector I'm willing to take some performance hit, this is going to be one of the only fe...

The problem is that implementing an accurate occlusion culling system is very hard even not taking performance into account. I would like to know why even one visible pixel needs to freeze the object? Why it needs to be that accurate? Would that then mean different game resolutions would result in different results? What does visible pixel even mean for something that is behind the camera and therefore not rendered? Is object being just slightly behind other object and it being registered as visible as bad as the other way around?

manic vector
# night raptor The problem is that implementing an accurate occlusion culling system is very ha...

It's just sort of nice to have it be completely in line with the rule of the game universe. The player would go for the entire game without seeing a single little thing move, so having it not be perfect would hurt a little. I would be willing to compromise on that last point though, if its just barely not visible, its fine for it to be counted as visible. Also a visible pixel would just be a visible pixel on the 360 degree view, like eg. if you put one camera facing up down north east south west.

oak marlin
# solar hill Check the pins here

Thanks for your help, however, I started one of the programming paths a while back but when I implement what I learned it's extremely jittery and doesn't work as well. I think it might be outdated

night raptor
#

More likely that you missed some part totally or made some little mistake

#

I think the learning pathways provide couple different unity versions to choose from. I would be surprised if the newest is outdated

oak marlin
night raptor
oak marlin
sour fulcrum
#

sounds good?

solar hill
#

unless you mean they want you to both add the rigidbody and use .translate?

oak marlin
sour fulcrum
#

what needed changes so it works

solar hill
oak marlin
sour fulcrum
#

no one cares to argue

#

figuring out what you did wrong is the first step to doing it right

#

if you have problems with the suggested answer people gave you

#

perhaps look online

oak marlin
#

Normally I go to ChatGPT to find tutorials online but that screwed up my past few projects and gave me horrible code. I wanted to talk to humans so I can actually find an educator or something

sour fulcrum
#

almost all 1:1 educators would be a paid situation

#

here we are happy to link to learning resources and help teach and troubleshoot specific pieces of knowledge

oak marlin
#

Well guess I am alone here, if I have any problems I will bring them here and hope someone can help 🙏

solar hill
#

we are always happy to assist with projects and individual problems

polar acorn
#

Unless it's Gorilla Tag

naive pawn
#

i don't think those ones count as individual problems

solar hill
#

or to find collaborators

#

quite litterally just making it someone elses problem lol

swift crag
#

oh dear

night raptor
# manic vector It's just sort of nice to have it be completely in line with the rule of the gam...

To elaborate on the point about pixels beyond the screen: let's say you have an object from which only one third of a pixel worth of corner pokes out from behind other object. If you render that view, it will depend on the exact alignment (and whether MSAA is enabled perhaps) whether that object has 1 or 0 pixels visible. Unless you use some exact mathematical solution (which is probably really hard and slow), even rendering the scene from all sides and counting the pixels would not give 100% accurate results.

One more problem that you probably haven't thought of, let's say you have an object A which moves really fast, let's say 10 units a second. Rendering at 100fps, that would mean movement of 0.1 units every frame. If A is coming from behind other object B but is this frame still barely behind B, you would allow A to move. That would cause almost 0.1 units of A becoming visible from behind B which would seem like movement to the player albeit only for one frame (then it would be visible and stop). Add a moving camera to the mix and it will probably become a nightmarish task to perfectly prevent this problem from occurring while maintaining any form of acceptable performance whether that means 1 or 100fps.

All I'm trying to say is that a perfect occlusion culling system like this is really really hard to implement if it needs to be perfect down to a single pixel or even more. At that point we are in a territory way beyond beginner code

manic vector
# night raptor To elaborate on the point about pixels beyond the screen: let's say you have an ...

In terms of that exact pixel alignment problem, i am fine if we very slightly allow some leeway on the side of freezing objects that are barely not in view.
And i have thought about that problem of fast moving objects, and my proposed solution is for any moving object (the only moving object will be a simple cube) to have a "ghost" version of it, which is one frame ahead, and the actually visible version which follows it

night raptor
manic vector
night raptor
loud widget
#

Guys what to do with the void start function in this code i have no use for it
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BusScript : MonoBehaviour
{
public float speed = 5f;
void Start()
{

}

void Update()
{
    transform.Translate(Vector3.forward * speed * Time.deltaTime);
}

}

#

Just DM me

solar hill
#

this dude did not read the rules

radiant voidBOT
sour fulcrum
#

delete the function

#

ur welcome

rich adder
#

wanting ppl to slide in DMs for such a simple answer is mind boggling lol

wintry quarry
#

Feed it to your children

fickle plume
radiant voidBOT
night raptor
# manic vector This is true... Well, this is pretty much the only feature I need to get my game...

If it only included the visible viewport, I would also consider rendering the ghost only scene to a render texture with object IDs and then reading those IDs in compute shader but it being a 360 makes it that much harder to implement fast enough. Reading back from the GPU memory can also introduce delay of multiple frames so even that is probably not good enough for the viewport only solution

sour fulcrum
#

i dont think its 360

manic vector
# sour fulcrum i dont think its 360

If its not clear what 360 degrees means, i mean if you can draw an uninterupted line from the player camera position to some point on the object, it should be frozen

sour fulcrum
#

it is clear what 360 degrees means

#

it's just not that

#

hence why people got confused

#

if it is legit just 360

solar hill
#

im still honestly confused as to what 360 is supposed to mean here

sour fulcrum
#

then thats just raycasts

#

cuz shaders could not work there at all

#

since it would include stuff not in screen

manic vector
#

When i said 360 i was thinking in my head of 360 degree videos, but obviously what i had in my head didnt translate, sorry guys 😭 . The problem i had with raycasts was you have to pick sample points on the object, and you would need a lot to make it actually accurate, to the point that I was thinking thats pretty much what happens in rendering and that could be related to a solution

manic vector
night raptor
#

Bunch of raycasts is probably your best bet

lilac pulsar
#

Can somebody help, so All of my animations play in the beginning of my game, but after the game restarts and i´m in the main menu, if i press play it just doesn´t play the animations anymore, only the idle animation, from the main menu, even altough i made idle to Jog animation with speed greater than 0 and also no animation plays after i restart the game besides the idle animation from the main menu, like the death animation doesn´t play or the jump animation so literally nothing, this is my script for my character:

radiant voidBOT
lilac pulsar
naive pawn
#

try checking the animator window and see if the parameters are as expected

#

you should not be using transform.Translate if you have an rb

lilac pulsar
naive pawn
#

have you selected the relevant object

narrow dune
#

I´m trying to use [SerialiseField] Transform cameraTramsform for my CameraController but nothing is popping up in the inspector.. What am I doing wrong??

narrow dune
#

can´t see any

naive pawn
#

have you saved and recompiled

narrow dune
#

nope and I´m a dummie wdum by "recompiling"

solar hill
#

When you make changes in your code it needs to be compiled for the changes to apply

#

this typically happens when you save a script of any kind, it auto recompiles inside of unity

#

if you didnt save, or you didnt manually recompile, then the changes wont apply

narrow dune
#

yeah okay of course I save my files

solar hill
#

then are you positive its the correct script thats attached?

#

if you right click the script in inspector and hit edit script

#

what opens up

solar hill
narrow dune
#

100% the same script

solar hill
#

because its also "Serialize" not with an s

narrow dune
#

nono that´s written correx

#

shit typo again

solar hill
#

by hitting "edit script" in the inspector?

narrow dune
#

i did

solar hill
#

alright then the next logical step is for you to send the script here, and screenshot the inspector and show it to us

#

!code

radiant voidBOT
narrow dune
#

pasatemyst isn´t working how intended (never used it before)

solar hill
#

also its working fine for me

narrow dune
#

idk solution?

wintry quarry
narrow dune
#

Console I guess

wintry quarry
#

Make sure you're looking at the Unity console

narrow dune
#

I am

solar hill
#

also in general dont send code as .txt files

wintry quarry
#

Can you send us a screenshot of the console?

solar hill
#

some platforms do not embed those

narrow dune
#

this, had to start the game, didn´t do it before (my mistake sry)

wintry quarry
#

this is a runtime error

#

this won't cause the field not to show up. Either your code file hasn't been saved or Unity hasn't refreshed it after it did. You can force a refresh with ctrl+r. By default it should refresh automatically though, unless you disabled automatic asset refreshes.

narrow dune
#

ok it suddenly showed up thanks a lot

wintry quarry
#

My guess is you have automatic asset refreshing disabled.

narrow dune
#

where to turn it back on?

solar hill
#

also a bit unrelated to your issue... but where do you actually call your mouseinput function

narrow dune
#

I will.. in Update() but I won´t before I can actually use my Inputs

wintry quarry
narrow dune
#

thks

lilac pulsar
# naive pawn do fix this too

Sorry i´m a bit late, no it doesn´t fix it, i think it doesn´t really changes much, but i noticed something, so my fault, after the game restarts and i select the player, in the animation window it shows the exact same as before the game restart, so for example in the main menu its loading the idle animation and there is this loading bar in the animator, also if i hit play, the walk animation also has a loading bar, which means all the conditions work and the animations should play, but somehow they doesn´t

bitter pine
#

how would i go about animating a single character at a time with TextMeshProUGUI?

{
    float currentDelay = 0;
    textHolder.color = textColor;

    if (i < secondColorRangeMax && i > secondColorRangeMin)
        { textHolder.text += "<color=#" + ColorUtility.ToHtmlStringRGB(secondTextColor) + ">" + input[i] + "</color>"; currentDelay = delay2; }
    else
        { textHolder.text += input[i]; currentDelay = delay; }

    //play bounce anim

    SoundManager.instance.PlaySound(sound);
    yield return new WaitForSeconds(currentDelay);
}```

this is what i have for a simple dialogue system so far, but when each character gets added i want it to play small bounce animation. any help would be appreciated
verbal dome
#

Or just use the animator if you want to

bitter pine
#

its all good i got it workin 👍

jovial heron
solar hill
#

what do you mean by effect?

#

like visually?

jovial heron
solar hill
jovial heron
#

ok thx

livid granite
#

hi guys so m jus asking does anyone jnow how to use a unity asset package ?

grand snow
livid granite
solar hill
#

well that then depends on what asset it is

#

and what you are expecting to do with it

grand snow
#

Once "imported" its in your projects assets can be used as they instruct

solar hill
#

look for any documentation in the folders

#

or on the asset store page

livid granite
#

ok umm u see what this asset file seems to have is many texture shader files my goal is to use that in order to make a working ocean or such but when i searched about it it kinda looks too much complicated since it depends on some frequencies etc stuff that m really not interested to hear can anyone help ?

solar hill
#

so wait lol

#

you arent interested in trying to understand how the asset works

#

but we are supposed to be.... so we can help you get it working?

#

that doesnt seem quite fair lol

livid granite
#

m not asking u to know m just asking if u already know

#

since m just a begginer lol

solar hill
livid granite
#

k have anyone ever used the SUIMONO Water System asset pack ?

polar acorn
#

Unlikely. You should see what documentation and support the asset provides

livid granite
#

u mean among the files it has ?

solar hill
#

here

#

its on the asset store page

livid granite
#

k thx

elfin pike
#

im using classes like these in my game GCR for all game and LevelContentRoot for Levels. What pattern to use, if i have to give PlayerInput reference to player instance?

grand snow
elfin pike
grand snow
#

When i had level loaders like this that would init the scene and pass in all important references

elfin pike
#

my levels are prefabs. I load scene which has basic data and LCR, and only then level layout prefab created

grand snow
elfin pike
#

I could pass input reference from GCR to LCR, but how?

grand snow
#

With scene loading we can get root game objects if you want to avoid a Find by type

#

You can also go the route of a dependency injection system (custom or pre made)

elfin pike
grand snow
#

It could but I have already explained how it can be done manually

#

The alternative is some static manager that provides access to common data/references but comes with its own downsides

elfin pike
#

i could make them from abstract class, which has static value with reference. It wont work right?

grand snow
#

what?

#

Structuring your logic to move a reference to some class instance is not hard

elfin pike
#

for me it is.

grand snow
#

You just need a hierachy of "control"

#

But in this specific instance, player input just maps to input actions in an asset so this is easy to re setup elsewhere

#

But in general a hierarchy of control and design such as mvc can help produce cleaner code.

elfin pike
#

you want to tell me that i dont need playerInput class?

grand snow
#

But understanding design to move data where you want is still good to learn

muted sand
naive pawn
#

i feel like we've been over this...

#

!ide

radiant voidBOT
queen vale
#

Hello,
I was curious if anyone had any recommendations for learning game architecture/design as the scale increases.
I'm relatively okay when it comes to something small, but as the scope increases... I want to make something more.... modular/expandable?

elfin pike
queen vale
elfin pike
naive pawn
#

how you like

#

commonly, by feature or by type

pliant light
#

yo whats up chat
how do I unlock the cursor from the game/window? everytime I run my game the cursor enters the game I'm making something similar to desktopmate so it has to be free
I have disabled all character controlling components and I'm using code like this aswell but its not working:
void OnApplicationFocus(bool hasFocus){
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
}

ivory bobcat
pliant light
#

It's part of a bigger script, the rest of it is running so this one should too

sour fulcrum
#

assumptions are death

ivory bobcat
#

Should. You need to test if the statement runs.

pliant light
#

Alright give me a moment to debug it

#

it looks like it is being called, I'm not sure how unity handles it so im not sure where else to check

ivory bobcat
#

Can you show where you placed the log?

pliant light
#

void OnApplicationFocus(bool hasFocus)
{

    Cursor.lockState = CursorLockMode.None;
    Cursor.visible = true;
    Debug.Log("Cursor check succsesful!");
}
ivory bobcat
#

!code
How to post code btw for future references

radiant voidBOT
ivory bobcat
#

!code

radiant voidBOT
pliant light
#

its also being called every single frame so theoretically it shouldn't conflict with anything else
also gotcha, I joined like 3 mins ago lol

#

or rather even if it conflicts this one would come ontop

ivory bobcat
#

Are you locking the cursor anywhere?

pliant light
#

not me, I'm using kyle prefab, I disabled all his components though

#

the game is on screen right now, when I click it the mouse disappears, idk if this screenshot could help locate the problem

ivory bobcat
#

Try this:cs void OnApplicationFocus(bool hasFocus) { Debug.Log($"Before: Lock state is {Cursor.lockState}"); Cursor.lockState = CursorLockMode.None; Cursor.visible = true; Debug.Log($"After: Lock state is {Cursor.lockState}"); }

pliant light
#

I'm assuming none means it should be free right?

keen dew
#

The cursor is by default unlocked. You just have to find the component that keeps locking it, not much else you can do

pliant light
#

I'm very new to unity, this is my first project, do any of the defaults do that or should i only look at the stuff I imported like kyle?

ivory bobcat
#

Yeah, you're trying to unlock it multiple times but you've got something locking it prior to every application focus call

keen dew
#

Disable everything in the scene, then enable them one by one until the cursor becomes locked. Then you know which one is doing it

pliant light
#

yeah thats probably the best approach since the default is the mouse being free; should be pretty easy to find the source. thanks for the feedback everyone

kindred flame
#

Can someone help me make a text scroll view in unity?

#

I followed every step and went back over and over again and the list is not scrolling

#

Like it's restricted I can't drag down

grand snow
swift crag
kindred flame
#

So basically with buttons it works

#

But with a big text is not working

#

I'm trying to make a log scrollview

#

And I ended up making prefabs of log entries

neon sable
#

should you avoid using for loops in unity scripts?

#

or are for loops fine?

kindred flame
#

It worked

swift crag
swift crag
neon sable
#

idk when i was working on C/SDL stuff got slower when i used for loops for certain things, so i assumed using for loops in update would slow things down

swift crag
#

the golden rule with uGUI is that every element should either:

  • ask for the space it needs directly
  • use a layout group to ask its children for how much space they need
neon sable
#

trying to learn correct coding practice for unity

swift crag
#

so, for example, this would work

  • Content <-- vertical layout group, content size fitter
    • Log Item <-- vertical layout group
      • Text <-- TextMeshProUGUI component (this asks for the space it needs)
swift crag
neon sable
#

yeah its why im wondering if for loops are generally avoided unless you absolutely need them

swift crag
#

i mean, you use them when you need to do something many times

#

and you don't use them when you don't

#

yourt question sounds confusing to me; you're asking if you should put gas in your car

#

it costs money, but the car isn't very useful if it can't move :p

neon sable
#

i mean there is more than 1 way of implementing things, is what im saying lol

#

sometimes you can use a for loop, or you can look into whatever your implementing and find a more complex solution that saves time

#

so what im asking is: are for loops generally avoided if you can find another implementation, or is it fine just being hacky and using for loops

#

not sure how this is hard to understand

swift crag
#

a for loop is simply a way to execute a statement many times; there is nothing intrinsically "hacky" about this

kindred flame
neon sable
#

lol

kindred flame
#

There might be a solution for that but I can't think of it

neon sable
#

its like doubling an item, you can *=2 or you can just bit shift left

#

bit shifting left is 1 operatoin

#

*=2 is many

swift crag
#

you're going to need to provide an example of what you'd be "replacing" a loop with here

neon sable
#

or a more unity example and the reason why im asking it, i was about to array all my text for a certina use function and use a for loop instead of using a OnTriggerEnter with a trigger collider. Obviously the for loop would have still worked, but the ontriggerenter is cleaner

#

would it have been fine using a for loop, or do i avoid it, like ive been asking at the start

swift crag
#

i mean, yes, that is obviously better

#

but that's borderline-tautological: it's obviously not good to do something like

for (int idx = 0; idx < 1000; ++idx) {
  Debug.Log("Doing this for no reason.");
}
neon sable
#

it's not, its multiple methods for the same implementation

#

this is just redundant code

swift crag
#

and yes, using physics is often more efficient (and easier to reason about)

#

especially when you have a large number of possible interactions

swift crag
#

was the idea to check if you're close enough to each interactable object?

neon sable
#

checking if the player is near the text to make it visible

swift crag
#

Ah, okay, now this makes a lot more sense

#

You should have led with that :p

#

This comes up pretty frequently

#

note that checking a few distances every frame is extremely cheap

#

but I think the big win isn't that it performs better

#

it's easier to reason about

#

you don't need to have a giant list of every interactable object; you just need to detect that you've entered a trigger collider and see if it's part of something you can interact with

neon sable
#

yeah still getting used to unity/c# syntax

#

didnt even know ontriggerenter existed

#

gonna hate my life when i get to OOP

swift crag
neon sable
#

reason why i learned C lol

swift crag
#

there are a few incantations to remember

#

(e.g. that trigger messages require at least one of the two objects to be part of a rigidbody)

neon sable
#

hm thats weird

#

how come colliders dont trigger other colliders

swift crag
#

A collider without a rigidbody is presumed to be "static"

#

it doesn't move

#

there'd be no point in checking for collisions between them

neon sable
#

are interfaces the same as header files?

#

like assume you could make a header file that just includes all the files in your project with that specific method

#

its basically saying hey if this interface is mentioned in the class, it probably has the methods mentioned inside of the interface

naive pawn
#

they aren't really comparable at all

neon sable
#

how

naive pawn
#

they're completely separate concepts

neon sable
#

how

naive pawn
#

have you like, googled what interfaces are and what they do

neon sable
#

lmao

naive pawn
#

some level of prior research is expected here

neon sable
#

i mean bro you literally never give any info whatsoever this is the 2nd time now

sour fulcrum
#

my experience with c is super shit but the difference here is that header files point to something (no plural) that exists, no?

naive pawn
sour fulcrum
#

where-as interfaces exist as a kinda barebones promise of what will exist for whatever implements them, which could be multiple different interpretations

neon sable
#

i think you can have a method in a header file that doesn't exist, you are just expected to have that method

naive pawn
#

cool. that concept just doesn't apply to interfaces at all

#

because interfaces don't have methods, they declare methods

#

they say what needs to exist

neon sable
#

not comparable though

#

at all

#

in the slightest

#

lol

naive pawn
#

yeah

#

i'm confused what point you're trying to prove here

neon sable
#

that they can be compared..?

swift crag
#

you can compare apples and oranges, of course

#

there is an extremely tenuous connection between the two concepts

sour fulcrum
#

probably not a good example

#

those are very similar 😛

naive pawn
#

ah yes, "header files do X while interfaces do Y which are somewhat tangentially related, so they're comparable"

neon sable
#

header files tell another file hey this method exists, you can use it

#

from my understanding interfaces do the same thing as long as the method actually exists, and its universal

naive pawn
#

ok? i'd say interfaces don't really do that

swift crag
#

an interface is a type

#

e.g.

public interface Foo {
  public void Bar();
}

this declares a type namd Foo

#

if you implement this interface, you must implement a method with a matching type signature

#

The point of a C header file is to forward-declare functions so that the compiler can be aware of them before the implementation is provided (whether that be through a source file or by a library you link to)

neon sable
#

im just trying to find a way my brain can link the dots together thats all, and using C as a comparison

#

cause this class/OOP stuff is new to me

swift crag
#

I guess that both of these say "this function exists", but they do so in completely disjoint ways

naive pawn
#

"interface" just as a general english term just means a surface where 2 things meet
interface as in the c# keyword/type means you declare a generic surface that declares how 2 things can interact, but not in what way
when you create something that should be able to interact in a specific way, you use an interface to declare that and also let the compiler verify that it's correct

swift crag
#

You're going to infer things that don't really exist

naive pawn
#

if you're absolutely looking for links, then interfaces and header files serve similar roles for libraries, because they're used to achieve the same goal, declaring an API (though, for different levels of structures)
but that's not really relevant anywhere else you'd use interfaces

neon sable
#

so an interface:

  • universally tells every script, these methods exist
  • these methods can only exist if the class includes the interface
  • the class MUST use the methods if it includes the interface
  • this allows every script to call these methods and assume the other script has it, and if it returns null, we know it doesnt
naive pawn
#

interfaces work on types, not files. if you want to draw parallels to C then consider them as guarantees of struct function pointers existing that the compiler can check i guess lol

#

these methods can only exist if the class includes the interface
no

#

the class MUST use the methods if it includes the interface
must declare

#

this allows every script to call these methods and assume the other script has it, and if it returns null, we know it doesnt
if what returns null?

neon sable
#

getting the interface component

naive pawn
#

that's not a thing in c#

#

components are a unity thing

#

universally tells every script, these methods exist
c# doesn't really work on scripts. it works on classes/types

neon sable
#

alright man can someone else help

naive pawn
#

@neon sable are you familiar with c++?

neon sable
#

no

swift crag
naive pawn
#

c++ has a concept called "requirements" that's pretty similar to interfaces

swift crag
sour fulcrum
neon sable
#

am i in a beginner discord chat or stack overflow

#

what is going on here

naive pawn
swift crag
sour fulcrum
#

by making the c comparison you implied some background knowledge that is needed to try and explain the differences (imo)

neon sable
#

ur explaining it in a way thats giving off huge ego dump

#

but thats expected by devs

#

lol

naive pawn
#

how would you like me to explain it then

sour fulcrum
#

thats all in your head man honestly

neon sable
#

dont worry

naive pawn
#

i literally just directly answered your questions

#

...because you've already made up your mind and refuse to accept the answers you don't like?

swift crag
#

correct

neon sable
#

not ego dump though

sour fulcrum
#

its not

naive pawn
#

where is the ego

swift crag
neon sable
#

literally in the unity discord

naive pawn
#

i literally just stated facts

swift crag
#

This is a completely reasonable response

naive pawn
#

you asked. i answered

sour fulcrum
#

you asked why they are different, Chris is being very explicit in your wording because your giving off the impression you want that

neon sable
#

the gaslight is crazy

sour fulcrum
#

those little nitpicks aren't digs at you

neon sable
#

look how they answer questoins in the SDL discord

sour fulcrum
#

it matters

#

using a method and declaring a method are two very different things
scripts vs classes (and vs instances of classes) are very different things
c# casting and unity components are very different things

naive pawn
sour fulcrum
#

it's not being pointed out to dunk

neon sable
#

look at this

#

lmfao

naive pawn
#

you said this was ego, so i got the impression that you didn't understand my answers. i'm giving clarification

#

it's your choice to read that as further ego if you want

#

i think that says more about you than it does about me

swift crag
#

Correct.

neon sable
#

its very clearly obvious im new to c# terminology, and ur taking every thing i say is literal

naive pawn
#

right, so we're telling you now, early on

naive pawn
#

none of this is personal

neon sable
#

lol

#

stack overflow vibes

swift crag
#

This is a waste of time.

naive pawn
#

yes, we try to be helpful

neon sable
#

it is, please just stop and allow someone with patience and the ability to learn new people concepts

naive pawn
#

we're not gonna sugarcoat it and say you're totally right on the comparison

sour fulcrum
#

If your not happy leave

#

Honestly

naive pawn
#

we're gonna give you the truth

neon sable
#

im not happy with your responses, i want someone who knows how to teach someone to understand how it works

sour fulcrum
#

A majority of the people here would have given the exact same answer, if you aren't comfortable with that this isn't the place for you

neon sable
#

telling me that scripts and classes are 2 different things, i dont care about the terminology right now, that is automatic and i will learn it as i go along

#

i want to learn the concept

swift crag
#

we do, but you've wasted our time complaining about us

neon sable
#

the irony of saying im nitpicking

#

whiel you guys nitpick at specific things im saying

sour fulcrum
naive pawn
neon sable
swift crag
#

i also explained the concept and advised why you shouldn't try to relate interfaces to C headers

neon sable
#

no dev does at the start

frosty hound
#

What even is the question?

neon sable
#

i just need to knwo the concept

sour fulcrum
#

you literally don't know how interfaces work so no you don't literally know what you do and dont need to know

naive pawn
#

so we're trying to start you off on the right foot here

sour fulcrum
#

script vs class is very important when you yourself brought up the header (which is closer to a script based comparison) comparison

swift crag
naive pawn
swift crag
#

C# does not care about specific files

#

you do not "include" files, and it lacks the preprocessor macros of C

neon sable
#

yes i know, thats why i said if c had an include all

#

which doesnt exist

frosty hound
#

What does header files even have to do with C# and Unity? If this is a general coding question, it's not really appropriate here.

#

If you want to dive into those things, at least make it a thread.

swift crag
naive pawn
# neon sable i just need to knwo the concept

ok, then discard notions about header files and scripts entirely.

interface declarations say, this thing <interface name>, can do these things <methods>
anything that says it's an <interface name> must be able to do these <methods>, and thus anything else can use that thing as if it were an <interface name>

neon sable
frosty hound
#

In the context of Unity?

swift crag
#

when I TA'd a C++ class, I always made sure to use very accurate language

neon sable
#

yes

sour fulcrum
neon sable
naive pawn
#

that doesn't make it "context of unity"

frosty hound
#

Okay, so in the context of Unity there is no header files.

sour fulcrum
#

they know