#archived-code-general

1 messages · Page 320 of 1

torn dome
#

So the user can store and show custom 'pets' as there called.

knotty sun
#

no they cant, Program Files should never be used for user data

torn dome
#

I don't want it in the documents as it can get in the way. It's like how VTube studio works

knotty sun
#

you can use Application.persistenDataPath or streamingAssetsPath

torn dome
#

I think I found how to do it from docs using a web request and 'file://'

swift falcon
#

how do u all animate ur charactrs

torn dome
knotty sun
torn dome
#

I think the sprite render is broken lol

gray mural
torn dome
#

It's off target. You can see where it should be (green box)

velvet pebble
#

I this problem as simple as having the camera be the child of an object that moves during fixedupdate?

#

if so, why wouldn't the camera position be jittery even while not rotating?

hollow hound
#

Is there a way to automatically destroy particle system object when all particles disappear?
Can do it manually based on particle lifetime, but wonder if there is a better approach

hollow hound
#

I don't need to check if it's alive, think it will be better to use lifetime instead of checking isAlive every frame.
I asking of some mechanism like an event that is invoked when there is no particle left, or some auto destroy. Does something like this exist?

#

Legacy ParticleAnimator had autoDestruct (https://docs.unity3d.com/560/Documentation/ScriptReference/ParticleAnimator-autodestruct.html) property, that does exactly what I need, but it's obsolete now. Do we have something like that now?

knotty sun
latent latch
#

better idea. Don't check and estimate by a lifetime you set at the start

#

you don't always need to destroy the system asap. Let it disperse and linger then destroy

hollow hound
mossy snow
hollow hound
knotty sun
#

this is what we call 'programming'
You take the pieces that you have available and you put them together in a sequence rthat does what you want

hollow hound
knotty sun
mossy snow
latent latch
#

should be requeueing them if you're generating tons of them anyway

hollow hound
meager night
#

Hey, I'm using the StarterAssets 3rd person controller and whenever I use their prefab to unpack and swap only the meshes everything works fine, the character walks normally. However if I try to setup a character with a different setup (other skinned mesh renderers etc) the character walks suuuper slow.. Both are tagged as humanoids on the imports, have about the same height

What could be causing this issue? It was caused by the animator Apply Root Motion

compact carbon
#

this dosent appear to work. ive tested and i cannot use the force adding part, it just goes on its own

#

and it goes in more of a square, not a circle.

#

oh and once it gets to the last point it resets which i think i can fix

neon zinc
#

I have a observer pattern that notifies (from the GameController) when a level is completed. I have two Singletons subscribed to that observer, one is the GameDataController (that manage all the data and it save and loads it ) and a ProgressBarController (that updates some objects on the UI to let you see your progress and fails). The ProgressBarController does a Get to the Instance of the GameDataController¿If the notification is send at the same time how can I do to ensure that the info that is read from the progressBarController is the last info?

latent latch
#

have GameData notify the ProgressBar

neon zinc
neon zinc
latent latch
#

if you have a race condition, then they both cant be subscribed similarly, so the idea is the one you want to be notified first will then notify the next object itself

#

unless you can define the execution ordering with events, but I'm not too sure about that

neon zinc
# compact carbon this dosent appear to work. ive tested and i cannot use the force adding part, i...

Try changing the FixedUpdate() on SplineFollower to also uses forces instead of just setting the posittion. In this way the object will be receiving some different forces to move and to stay on the spline. Something like this:
void FixedUpdate()
{
t += Time.deltaTime * speed;
Vector3 targetPosition = CalculateSplinePosition(t);
Vector3 moveDirection = (targetPosition - transform.position).normalized;
rb.AddForce(moveDirection * speed, ForceMode.Force); // Adjust force as necessary
}

compact carbon
#

so i dont need force applier anymore?

neon zinc
neon zinc
compact carbon
meager night
neon zinc
compact carbon
#

ah oj

meager night
#

if you care about the latest one you should be able to "drop oldest"

neon zinc
meager night
#

There’s also an implementation of it from cysharp on the UniTask repo

gray mural
#

How would you implement the structure of the snake, which can move in the different directions and is affected by the gravity, although its rotation always stays the same?

#

Every 1x1 block represents the part of the snake's body. The number of the blocks can be changed. This way, adding 1 block to the snake makes its tale 1 block longer

#

I consider having a parent empty GameObject with the Rigidbody2D component, and the blocks with the BoxCollider2Ds

gray mural
leaden ice
#

It's Unclear what you mean by "structure"

gray mural
#

The way the object should be built in the game

gray mural
leaden ice
#

Use multiple boxes with a CompositeCollider2D

gray mural
ripe ember
#

you can use OnCollisionEnter2D(Collision2D collision)

First get the collision point with "Vector2 collisionPoint = collision.contacts[0].point;"

next you get collider's center point "Vector2 colliderCenter = collision.collider.bounds.center;"

next calculate distance between point and center "float distanceToCenter = Vector2.Distance(collisionPoint, colliderCenter);"

compare the distance "if (distanceToCenter < cornerThreshold)
{
Debug.Log("Player hit the corner of the collider.")
}"
float cornerThreshold = 0.1f; (you can adjust this threshold)

dim forge
#

hey, how can i rewrite this in a way that lets me build the game?

knotty sun
#

use Resources.Load
AssetDatabase is Editor only

oblique spoke
#

Or Addressables.

dim forge
#

im trying, but it doesnt work

#

no clue why

knotty sun
#

ffs another 'doesn't work'. Explain please what doesn't work

dim forge
#

i mean that it doesnt load, im trying to instantiate a nulll object

knotty sun
#

Ok, so what path are you using for Resources.Load? And please go and read the documentation as well

dim forge
#

right, just found that the path has to be relative to the resources folder

#

will try with that

knotty sun
dim forge
#

yeah, no extensions

loud wharf
knotty sun
loud wharf
#

Yeah true that.

#

Anyways. I'm wondering if there's something that exists with these characteristics:

  • Globally accessible fields like a singleton or static.
  • Fields accessible and serialized in the editor and can reference assets like a scriptable object.
heady iris
#
using UnityEngine;

public abstract class SingletonSO<T> : ScriptableObject where T : SingletonSO<T>
{
    private static T _instance;

    // only really needed for the editor when Domain Reload
    // is disabled.

    public static bool InstanceExists => _instance != null;
    public static void ClearInstance() => _instance = null;
    public static T Instance
    {
        get
        {
            if (_instance == null)
            {
                _instance = Resources.Load<T>("SingletonSO" + "/" + typeof(T).Name);
                _instance.OnLoad();
            }

            return _instance;
        }
    }

    protected virtual void OnLoad()
    {

    }
}
#

you can ignore the InstanceExists and ClearInstance parts if you have Domain Reload enabled

#

I use those to look for the singleton and get rid of it when the game starts

heady iris
knotty sun
heady iris
#

e.g. Resources/SingletonSO/MySingletonType for a class called MySingletonType

#

I use this for "catalogs" of other assets

heady iris
loud wharf
#

Yeah that makes sense.

#

Seems like using Resource is about the way to go.

#

I found Unity localisation while trying to find other ways.

heady iris
#

I was originally planning to do this with Addressables

#

but nothing else in my game is using Addressables, so it was not a good fit

#

this is not a code problem

#

zoop

loud wharf
#

Real.

slate jacinth
#

can someone please help me my unity editor wont download it just keeps "validating"
does anyone know how to fix this?

heady iris
#

this is still not a code problem

loud wharf
#

Btw, SingletonSO are used for storing sounds to use with id system for example right?

#

Just looking for some use cases. UnityChanThink

#

But I do have the feeling directly referencing something might limit me in some ways.

heady iris
#

either the AudioClip itself or some other asset

loud wharf
#

I did remember some people dumping all their sounds into one library.

heady iris
#

Most of my SingletonSOs are either:

  • the root of a hierarchy of assets (e.g. the root Settings category)
  • a service (e.g. a class that can give you an icon that matches an InputBinding)
#

some are also just a bundle of references that I need in many places

#

that would be annoying (and error-prone) to manually assign

#

I need to write a validator to make sure I'm not missing any singleton assets

#

get all children of SingletonSO -> try to load each one

loud wharf
#

Ah.

#

Seems neat thanks.

loud wharf
heady iris
#

i can automatically check if any of my entity prefabs have a missing reference

loud wharf
slate jacinth
heady iris
#

you also ignored my last request, so...

knotty sun
slate jacinth
#

its not i js wanted help

knotty sun
#

we have different channels here for a reason, you ask your question in the correct chanel and, maybe you will get an answer

slate jacinth
#

well i didnt in the other channel

knotty sun
#

you certainly wont here

hollow hound
#

How to create visual effect graph? I don't have an option from the screenshot. Do I need some package installed for this?
unity 2021.3

heady iris
#

It's a package, yes.

hollow hound
#

Found it, thanks

candid elm
#

just a simple question i wanna gather some experience working in a team is there any place where i can collab with people

heady iris
#

!collab

tawny elkBOT
heady iris
#

also, not a code question

#

which would be more appropriate than those forums, which would be for specific projects

candid elm
#

thx

livid loom
#

I almost got banned last week for saying I don;t use Coroutines and have my own time based functions and I don't see why to use them

#

Scroll up man seriously actually happened

heady iris
#

ok

spring creek
livid loom
#

Asking why use Coroutines is off topic?

spring creek
#

And now you are randomly dragging it up again to whine more

livid loom
#

whats with Unity people thinking coroutines are normal thing in every negine most engine don't cripple while loops? I did I simply asked why use coroutines I don't see how they are better then writing you own time based functions?

#

they jumped down my throat to the poiin ta mod said I had to tell him that I lvoe Coroutines

knotty sun
#

I think it was more a case of I know best because I live in a city where other people make video games

heady iris
#

no, you filled the channel with garbage and a mod had to get involved to make you stop

#

as you are doing now

livid loom
#

nevermind

spring creek
#

they jumped down my throat to the poiin ta mod said I had to tell him that I lvoe Coroutines

Objective lie

livid loom
#

I have screenies

spring creek
# livid loom I have screenies

I read it all. Everything you've said about it is a lie.
This channel is for getting help and giving help. (Even saying it was a week ago. That was yesterday...)
Not for whining

Please stop

livid loom
#

asking queston about the engne is not whining lol

#

you know please ban lol

spring creek
livid loom
#

Ill report discord to Unity because we are sick you guys BS tons of forum posts about how mods run this place it's like a bunch of 15 year olds in here thanks

heady iris
#

please leave, child.

livid loom
#

no ban me

spring creek
#

So you want to go around saying "they banned me for asking about coroutines"
When it is really that you are being a nuisance and attacking people for no reason? Gotcha. Best of luck with that pitiable behaviour

heady iris
#

okay. <@&502884371011731486> obvious troll

cosmic rain
heady iris
#

when you described getting banned from another server for some kind of deltaTime-related argument, I got a very clear picture in my mind of how that went down

knotty sun
#

I can just imagine this server being run by 15yo's. 99.9% of posts would be idk and wdym

cold parrot
#

We need a name for this archetype: maybe „Passive aggressive learner“

sleek bough
tawny elkBOT
#

dynoSuccess mouse8763 has been warned.

heady iris
#

let's not contribute to the spam further, and end this

lyric nymph
#

Hi yall, just need some confimation on how the child gameobject works, when a child gameobject gets destroyed in runtime, the index of the child gameobject remains right? if so how do I remove this empty index so a new instantiated child can take its place?

heady iris
#

A useful trick is to set the child's parent to null before you destroy it

#

This gets it out of your list of children.

#

You may want to insert the new object with SetSiblingIndex before you destroy and unparent the old object

lyric nymph
#

Ohh this is incredibly useful thankyou.

plush sparrow
#

Anyone knows how to get transform rotation values that are > 90 ?

lusty zephyr
gray mural
#

No, it's better to say "converts"

lusty zephyr
gray mural
#

It, probably, should

plush sparrow
gray mural
plush sparrow
#

Target.localEulerAngles.x returns values upto 90°

#

More than 90 it' starts decreasing the output

gray mural
#

So it simply starts going down

gray mural
#

What exactly do you want to achieve though?

plush sparrow
#
using UnityEngine;

public class SetHandSpring : MonoBehaviour
{
    private HingeJoint joint;
    public Transform target;


    void Start()
    {
        joint = gameObject.GetComponent<HingeJoint>();
    }

    void Update()
    {
        JointSpring spring = joint.spring;
        var angle = 0f;

        angle = target.localEulerAngles.x; // Right
        spring.targetPosition = angle;
        joint.spring = spring;

    }
#

I have a hand
It has a rigidbody, hingejoint and box collider.
And I have a seperate "target" Game object

#

I want to calculate the targets x axis angle, and add that angle to my hand objects hingejoint spring value.

plush sparrow
gray mural
#

Unless it's your custom class you're using

plush sparrow
#

Ignore that

gray mural
#

This should thus throw you an error

gray mural
plush sparrow
#

Ignore the joint part

#

My issue is with the "angle"

#

How should I gather rotation.x value as it shows in the inspector

gray mural
#

It doesn't seem to be wrong

plush sparrow
#

But that doesn't work after 90°

#

Since euler angle range is different

gray mural
#

Oh, you have a 3D project, don't you?

plush sparrow
#

Yeah

gray mural
#

Then you also have 3D objects?

plush sparrow
#

Yeah

gray mural
#

The x rotation should be alright.

#

It should go from 0, all the way up to 360 deg

ripe ember
plush sparrow
#

Hey thanks
Will try and update you guys

gray mural
#

Still, I wonder whether eulerAngles can ever return a value, not clamped within -180 and 180

gray mural
#

I see

But eulerAngles will return you the same value within 0 to 360 range.
However if you will rotate object in script, unity will keep values in editor within -180 to 180 range.

plush sparrow
#

Same result

#

If in inspector I give rot.x value as 85
Output is 85 from localEulerAngles.x
If I set 90
Output is 90
If I set 95
Output is again 85

#

Is there anyother way to do this other than euler angles?

ripe ember
#

then you can use Quaternion and then transform Quaternion to euler

plush sparrow
ripe ember
# plush sparrow Could you elaborate please?
{
    if (joint == null || target == null)
        return;

    JointSpring spring = joint.spring;
    Quaternion targetRotation = target.localRotation;
    Vector3 targetEulerAngles = targetRotation.eulerAngles;

    float angle = targetEulerAngles.x;
    if (angle > 180f)
        angle -= 360f;

    if (angle > 90f)
        angle -= 180f;
    else if (angle < -90f)
        angle += 180f;

    spring.targetPosition = angle;

    joint.spring = spring;
}```

try this
plush sparrow
#

Will try sure thanks

ripe ember
#

if that doesnt work try to remove

        angle -= 360f;

    if (angle > 90f)
        angle -= 180f;
    else if (angle < -90f)
        angle += 180f;```

this part and see what you get
plush sparrow
plush sparrow
latent latch
#

Ideally use Quaternion.AngleAxis if you're working 3D

plush sparrow
#

But I need the angle value

#

I have one object

#

And I have a hand object with a hingejoint that has a spring parameter
I want to assign the rot.x value to the spring value of the hand object

latent latch
#

well, start debugging and seeing if your values are correct step by step. Dijabola has given some ideas

heady iris
#

you still haven't shown what the scene looks like. i'd really like to see how things are arranged

plush sparrow
#

Oh

#

Sorry about that

#

Please tell me what info you need

heady iris
#

An image that shows the target object, as well as how it rotates

#

make sure it's on "Pivot" and "Local" up here

plush sparrow
#

Yeah they are on pivot and local

#

Ok sure

#

Just a sec

#

The red one is the "hand"

#

The white one is the "target" Name as left shoulder

#

Based on the left shoulders (target) x axis rotation
The hingejoint ,spring target position, of the "hand" will be assigned

heady iris
#

and you need to measure how far the shoulder has rotated around the red axis in the second image?

plush sparrow
#

Yeah

heady iris
#

Rotating the object around the red axis changes all three X/Y/Z euler angles

plush sparrow
heady iris
plush sparrow
# plush sparrow

So if I can provide the x axis angle here
It will do the rotation of the hand for me

#

Localeulerangle.x is giving x rotation valye

#

But only till 90°

#

Is there any other way
You would rotate an object?
For eg I have 2 objects
If I move on object in the scene through inspector
I want the other object to copy and rotate similarly
Is there any way to do that?

heady iris
#

so you want the hand to behave like it's parented to the shoulder?

plush sparrow
#

But parenting it won't work
It will already be parented to the body

heady iris
#

the hinge joint already does this: as I rotate the parent object, the child spins around it

plush sparrow
#

I can't parent it to the target

heady iris
#

The cubes are siblings. That's just how a hinge joint works

#

oh

#

that recorded nothing, oops

plush sparrow
#

Yeah

heady iris
plush sparrow
#

I can't parent it to the target
Parented to the body already

heady iris
#

Nothing is parented here.

plush sparrow
#

Hmmm
But that's not what I am looking for
If I rotate target
The hand should rotate equally
Is what I am looking for

#

Is there any other way I can track angle change?

heady iris
#

I need to see an example of the movement you're trying to create, because I don't understand what it is

plush sparrow
#

Yeah I will try screen recording and sending

#

Just a min

heady iris
#

ah, okay, you are rotating the shoulder around the axis of the hinge

#

so you need to update the hand joint to try and match that

plush sparrow
#

Yeah

#

I needed angle value for that

#

Rotation axis value for that

dense estuary
#

I need to create a inventory system. My plan is to go through this in steps. The first step is to create a scriptable object to store item data. Currently I have a scriptable object that stores upgrade data, but I am going to have multiple kinds of items, not just upgrades.

#

The upgrades are little computer chips that you can find in buildings. What I want to do is make an inventory system so you can pick the upgrades up and choose which ones to use on the radar. But I also want the player to be able to find other types of items like food and water.

#

How can I go about creating a scriptable object that holds item data, while also being able to hold extra data from upgrades?

heady iris
# plush sparrow

figuring out joint rotations is a bit of a pain -- I'm still kind of unclear on the math involved. I did find one thing that might be useful, though

#
    void Update()
    {
        var spring = joint.spring;
        spring.targetPosition = -joint.angle;
        joint.spring = spring;
    }
#

wait, actually, why not just set it s target position to zero?

#

(this does something similar, but it's much more wobbly)

plush sparrow
#

target position of the spring from hingejoint?

heady iris
#

joint.angle is the angle between the two rigidbodies (relative to how they started)

plush sparrow
#

targetposition of the spring is 0 at first

heady iris
plush sparrow
#

i need to increment and decrement it based on the Targets x rotation value

empty pelican
#

I've been stuck on this for hours and I'm stumped as to where to start

lean sail
jaunty sleet
#

does anyone know how to write a script for unity that interacts with the verticies of a mesh? Like if I wanted to try to create a softbody physics script. Or do I have to learn how to write shaders to do this?

dense estuary
#

@heady iris Alright, I'm a bit confused. I have 2 scriptable objects called UpgradeSpec and ConsumableSpec. I have a single non-monobehaviour script called ItemData. How do I store the data unique to each upgrade or consumable?

cold parrot
dense estuary
fallen lotus
#

Are unity events reccomended to be used? Such as:

Something like where one script has:

OneScript.cs

public static event Action OnButtonPressed;

public void AnimationFinished() {
    OnButtonPressed?.Invoke();
}

and another script will do something when that action is invoked such as

AnotherScript.cs

private void Awake() {
    StartButton.OnButtonPressed += StartGame;
}

private void StartGame() {
    for(int i = 0; i < 4; i++) {
        SpawnCard(i + 1, (Card.Suit)i + 1);
    }
}
cold parrot
fallen lotus
#

I've heard things that they are like resource intensive but I just wanted to ask if they are like reccomended

chilly surge
#

Unless you are subscribing/unsubscribing thousands of times per second, I wouldn't worry about it.

cold parrot
#

that article seems to conflage memory allocation and garbage

#

technically its only garbage if the memory gets released. Typically "garbage" is memory allocated repeatedly for single use which is then "discarded".

leaden solstice
#

C# event basically creates new array every time you subs/unsubs so that’s that

#

UniRx could be alternative

cold parrot
#

how does that solve allocations?

leaden solstice
rigid island
fallen lotus
rigid island
#

indeed

fallen lotus
#

okay i see

rigid island
#

I usually do
OnEnable() event += method
OnDisable() event -= method

loud wharf
leaden solstice
untold stream
#

anyeone know how to stop my pixels in a pixel eprfect camera to stop turning grey from a perfect white. they keep blending togetehr for some reason

rain lava
#

What is the problem why it becomes null

#

TMP_Texts are not null

#

same thing happens even if don't put conditions or if(occurrence==null{ occurence=this} in awake

#

I used Start instead of awake or both same error

somber nacelle
#

which is line 65

rain lava
#

objective completed comment

#

it is pickup gun system

somber nacelle
#

then ObjectivesComplete.occurrence is null

rain lava
#

it becomes null idk why

somber nacelle
#

well you probably have more than one of those components, so when the second one runs Awake it assigns null to the occurrence variable

#

also that else if isn't comparing to this it assigns to this (though that is not related to the current issue)

rain lava
#

5:54 he does same thing

#

no error

#

but in comments there are a lot of guys getting same error

somber nacelle
#

the error is due to the issue i just pointed out in the ObjectivesComplete class

#

not due to the line of code that is being written at that time stamp

rain lava
#

should i use empty object for this static class

rain lava
#

and add something like dontdestroyonload

somber nacelle
rain lava
#

i mean unity does that

somber nacelle
#

it is not an issue with the priority of Awake

#

you literally assign occurrence to null if it isn't null

#

your singleton is set up incorrectly

rain lava
somber nacelle
#

wdym you "did other things too"

rain lava
#

same error

#

or without if

#

same error

somber nacelle
#

then this is likely an issue with the order your code runs in. do not access the singleton until Start at the earliest

rain lava
#

It is about setactive() thing

#

when parent object is gone it automatically becomes null

somber nacelle
#

set active will not make that variable null. only destroying the object after it has run Awake will make it null unless you explicitly assign null to it somewhere

rain lava
#

sofa was active and i shared its codes

#

player hands are inactive

#

when you press key it activates that

#

and other one is inactive

somber nacelle
#

that is all irrelevant

rain lava
#

but now it worked

#

i used that error line in hand gun

#

when you first use with awake

#

it worked

#

this time

#

hard to explain without video but i solved

somber nacelle
#

what part of "do not access the singleton until Start at the earliest" do you not understand?

upper pilot
#

How can I prevent clicks from deselecting UI buttons?

        EventSystem.current.SetSelectedGameObject(FirstSelectedButton);

I use this to select a button when I open specific UI object, but clicking outside causes it to lose that object and I have to left click + hold over an object(but release outside it so I don't click it) in order to "fix" the issue.
The game will use controller to play either way, but it would be nice if I knew how to avoid this type of issue in general.

latent latch
#

Eh, maybe need to catch the user clicking outside and set back the selected gameobject

upper pilot
#

Is there another way? This seems kinda hard lol

#

So this is meant to send "OnDeselect" to a previous object after you select a new one, so it snot exactly what I want, but maybe it works.
The problem is that I'd have to create a script for those buttons which I dont really need/want.

latent latch
#

getting away with unity ui and utility without scripting is wishful thinking

upper pilot
#

It is preferred to have only 1 EventSystem in the scene right?

#

It's not required, but its not explained why would that be needed.

latent latch
#

it's just an optional parameter it looks like

#

which probably defaults to current event system

leaden solstice
#

Not EventSystem

upper pilot
#

Missed that, still not sure what it does.

leaden solstice
#

That’s why it’s named pointer

#

As in mouse cursor

upper pilot
#

Got it

#

I am trying to find a way to Get currently selected button with this method:

EventSystem.SetSelectedGameObject

I tried .currentSelectedGameObject but it returns null

#

After 2nd try, it seems to be selecting it properly now 😮

terse turtle
#

I'm quite new to using Animations to trigger things like attacks. I want to know if I would be piling myself into technical debt if I use animations to trigger attacks. Instead of using code to do so sadok

upper pilot
lean sail
waxen blade
#

I have a Coroutine that can be launched via the StartCoroutine method, and different classes are activating this Coroutine. I have another method that stops the Coroutine.

If a different class other than the one that started the Coroutine tries to stop it, I get this exception in the console:

"Coroutine continue failure"

I did research on this. This doesn't actually cause any problems, it just generates the error. The workaround is to make sure that the same class that started the Coroutine also needs to be the same class that stops the Coroutine. But the problem is, I won't always know which one is going to stop the Coroutine.

I don't want to have to implement interfaces or make things more complicated that it currently is to work around this. Is there an easier way to prevent the error or ignore it?

leaden solstice
#

Alternatively have a dedicated object that runs coroutine so you can always call thru that object

waxen blade
#

On your first suggestion, I believe I'm already doing that. but I think your second suggestion will work.

#

I like it. I'll try it, thank you.

lean sail
#

Im getting this error with no stack trace, is there something specific that causes it?
I have a Character poco which i made serializable temporarily so I could see it in inspector. Theres really nothing special going on with it. https://gdl.space/vulemakepo.cs
The error doesnt seem to affect anything, but its just annoying to see.

tawdry dirge
#

Can someone very smart explain the difference between Manhattan and Euclidean distance? I get that they produce different values but surely, when using them for pathfinding, the values are gonna still be in the same order of smallest to largest regardless of which distance you use?

somber nacelle
lean sail
#

the error is somewhat random and doesnt always happen, but I will see if that solves it

somber nacelle
#

this is kind of an oversimplification, but should help you understand how they are different

tawdry dirge
#

Like, I don't get the difference when applied to A*

cosmic rain
#

It might have a different meaning in the context of the algorithm. Might want to share where specifically you're reading about it

tawdry dirge
#

It's a background explanation for my diss. But I can't think of an algorithmic difference between the two

somber nacelle
lean sail
#

its really just a difference of what heuristic values you are providing

#

heuristic has to be the value where no real solution is shorter

round creek
#

hey, i'm trying to use physics2d.istouchinglayers to no avail and i'm not sure why. i've looked through online forums and documentation, but i can't seem to find a solution.

colliders in question: circlecollider2d and polygoncollider2d
both colliders are on the same layer

any help would be greatly appreciated.

tawdry dirge
#

It's a different ratio when compared to the G cost right?

#

I mean, that's what makes sense in my head

#

Ok so I forgot that A* works with G+H, I was thinking about how the H values are still in the same order but when G is added, they're not necessarily

lean sail
#

there are papers on what the difference results in even

somber nacelle
# round creek hey, i'm trying to use physics2d.istouchinglayers to no avail and i'm not sure w...

https://docs.unity3d.com/ScriptReference/Physics2D.IsTouchingLayers.html

It is important to understand that checking if Colliders are touching or not is performed against the last physics engine update i.e. the state of touching Colliders at that time. If you have just added a new Collider2D or have moved a Collider2D but a physics update has not yet taken place then the Colliders will not be shown as touching. The touching state is identical to that indicated by the physics collision or trigger callbacks.
go through this to troubleshoot: https://unity.huh.how/physics-messages

tawdry dirge
round creek
lean sail
somber nacelle
tawdry dirge
#

Surely it's just THE value it predicts

lean sail
# tawdry dirge Surely it's just THE value it predicts

the heuristic is an estimation. if you had THE value then you wouldnt need a pathfinding algorithm at all because you would already know the best path.
different algorithms give different results, thus the best heuristic gives you the largest value, the most accurate value. Think of it like this, you are told to walk to the nearest park. Before leaving you ask one person how far it is, they say 5 minutes. You ask another person, they say its 10 minutes away. The park is 15 minutes away in reality. The 2nd person gave you a better answer, both were underestimations but one was closer.

#

now if one person said 20 minutes, this would be bad.

tawdry dirge
lean sail
#

well if it were too big, then you would be overestimating the distance and the algorithm wouldnt work

tawdry dirge
#

Yeah well if you applied Euclidean distance to a grid where you can only move up, down, left or right, it would underpredict surely?

#

Ignore that hang on

#

brain whirring

lean sail
#

yes, manhattan would be better there

#

if you had a grid where you could move in 8 directions, manhattan would overpredict and is useless

tawdry dirge
#

Ahh I see I see

#

See yh, I forgot the size of the number mattered. I thought the only thing that mattered was the size in relation to the H values of other cells

#

Forgot it's G+H, not just H

#

Thanks

round creek
somber nacelle
round creek
#

dang

#

is there any way i can detect whether a collider is overlapping with something else without having a rigidbody on it?

somber nacelle
#

a physics query like an OverlapCircle or something like that

leaden ice
#

Why do you need to not have a Rigidbody

drifting star
#

What are the [SerilizeField] thingys called? Like the part where you do the [].

somber nacelle
#

attributes

drifting star
#

Ah, thanks!

lean sail
#

I'm still having this issue if anyone has clues. #archived-code-general message , error "Unsupported type Character" with no stack trace. I added a parameterless ctor but its still happening.

#

🤔 Ive seemed to narrow it down to a specific object in my scene, a target dummy who if I delete (and undo deletion) get more errors. Guess this isnt an issue with the code then.

knotty sun
lean sail
knotty sun
leaden solstice
lean sail
#

i see

lean sail
#

its probably my fault because Character used to be the monobehaviour, which i renamed to CharacterBehaviour. Then created a poco Character.

leaden solstice
#

Ah then it sounds like meta issue sure

#

Your GO probably has that old reference

#

When you rename class file make sure you rename meta as well

knotty sun
#

you might even need to delete the Library folder as you may have a corrupt AssetDatabase

leaden solstice
#

Just delete that meta

lean sail
#

I renamed it through VS, compiled, and then made Character later but idk. Ill try library if I get the error again because at least i can recreate it now

knotty sun
#

AH, wrong, I never rename stuff in VS

leaden solstice
#

Rider automatically rename meta, but not all IDE does that

#

If you rename in Unity it will be rename meta as well

knotty sun
#

indeed

lean sail
#

damn didnt know that, Ive been doing this a lot and its the first issue ive had. I even suspected this might be an issue, but figured it was fine if i let it compile first

knotty sun
#

if you didn't have so many references I would say delete it and add it back but I guess that is not an option

lean sail
#

since this is just the poco i can delete it, its not actually used in inspector. i just have it serializable so i can easily see what characters my enemies are trying to target

#

oh you meant the monobehaviour probably

knotty sun
#

but if you delete it you will get compile errors which will mean Unity wont update the Assetdatabase and meta files

lean sail
#

i see, well worst case ill just remake the target dummy because im fairly certain this is only an issue with that one object

leaden solstice
#

Don’t you have something like "script cannot be loaded" in your GO that has problem?

lean sail
#

ill have to deal with that later though, something else in my project has gone really wrong 👀

leaden solstice
#

Yeah if you see that you can remove that script and add back (Or use debug inspector to swap script)

lean sail
#

somehow along the way i also had a major issue with newtonsoft which involved deleting it as a package for it to recognize as a namespace. im too tired and confused for this right now

knotty sun
#

Definitely sounds like a meta data fuck up

lean sail
#

thanks both for the help

knotty sun
#

np

torpid beacon
#

I didn't know where else I could post this so pardon me if this is the incorrect channel.
I currently use Unity Version 2022.3.22f1 (also had same issue on 2022.3.5f1 and 2021.3.12f1 across multiple projects).

I have not been able to make a proper build at all the last week or so. I keep getting failed build attempts with similar errors relating to this same Library\Bee\artifacts... file path. In this case, I am trying to make a WebGL build but I've had similar build fail errors with Windows builds as well. The only exception was when building using the Mono scripting backend for a windows build. I have had a hard time trying to figure out whats up and would appreciate anyone that has some insight.

torpid beacon
thick terrace
# torpid beacon

i wonder if there might be more detail in the full editor log file?

torpid beacon
thick terrace
#

click on the three dots on the console window

torpid beacon
#

it is extremely long. Would linking the whole thing fine?

rain lava
#
using System.Collections.Generic;
using UnityEngine;
using TMPro;

public class ObjectivesComplete : MonoBehaviour
{
    [Header("Objectives to Complete")]
    public TMP_Text objective1;
    public TMP_Text objective2;
    public TMP_Text objective3;

    public bool obj1comp = false;
    public bool obj2comp = false;
    public bool obj3comp = false;

    public static ObjectivesComplete occurrence;

    private void Awake()
    {
        occurrence = this;
    }

    public void GetObjectivesDone(bool obj1 = false, bool obj2 = false, bool obj3 = false)
    {
        if(obj1 == true && obj2 == false)
        {
            objective1.text = "1.1: GOREV TAMAMLANDI";
            objective1.color = Color.grey;
            obj1comp = true;
        }
        else if(obj1 ==true && obj2 == true)
        {
            objective1.text = "1.2: GOREV TAMAMLANDI";
            objective1.color = Color.grey;
            obj2comp = true;
        }
        else if (obj1 == true && obj2 == true && obj3 == true)
        {
            objective1.text = "1.3: GOREV TAMAMLANDI";
            objective1.color = Color.grey;
            obj3comp = true;
        }
    }
}
#

This static occurrence still becomes null

#

where is the problem

#

this error comes from another class that uses this static class' function

#

when i use debugging, it doesn't even come to static's awake

thin aurora
#

Please share your !code using a paste site

tawny elkBOT
rain lava
#

I mean there is not complicated command

#

only calling

#

still becomes null

thin aurora
#

Try logging ObjectivesComplete.occurrence at the beginning of the start method of ObjectivesComplete and Rifle

#

Also, is occurrence possible assigned anywhere else?

rain lava
#

I checked out didnt find, only command calling nothing more

mellow sigil
#

Do you have an active object on the scene that has ObjectivesComplete as a component?

rain lava
#

No

#

this could be problem

mellow sigil
#

Well yes, Awake will never run then

rain lava
#

should I use active object everytime?

#

empty

thin aurora
#

Yes

#

The whole point of components is having them on game objects

#

Then forget the logging part, just assign the script to a new empty gameobject specific for this

rain lava
#

Then I should create some empty object where it has static component

#

and others access that

#

like gamemanager

thin aurora
#

If this is weird and you don't want to assign this on a game object, then just use a normal class and assign this in the constructor

#

Yes they can, that's what the static field allows

rain lava
#

I will use this system on another objectives completed messages changes

#

like 1) some mission info => use static to change text | new 1) you completed

thin aurora
#

Sure, but I would reverse the logic and have the manager change its own data

rain lava
#

I tried making this system

thin aurora
#

Have it subscribe to events rather than allowing outside behavior modifying its state

#

The latter is just messy and unreadable

rain lava
#

I couldnt get used to using events,interface and ienumerable yield systems but i can try

#

I know they are really useful but

#

Yes i solved problem it is really about inactive gameobjects

#

you should always use always active gameobject for static

thin aurora
#

Events are not hard

#

Just write one for whatever object would otherwise update the UI and have it be a meaningful event

#

Like if an Enemy would update some "alive" counter, just make a "died" event and have an UI manager subscribe to that in order to update its counter

rain lava
#

I need to be comfortable to use them like using void function(parameter 1,parameter2)

#

Need to make 5-10 example about it

swift falcon
#

hey guys can anyone help me, trying to make my car controler turn, but its not working, well, it is and it isnt, itsd resetting its y position to 0 but not turning over time like it should be... ive included images as well to help, but i dont know what im doing wrong there is a ridgidbody on the car so that it has physics ands everything but i dont get why it isnt turning.

void Update()
    {
        Child = this.gameObject;
        //Debug.Log(Child.name);
        localrot = (float)Child.transform.rotation.eulerAngles.z;
        //Debug.Log(localrot);
        angle = this.transform.rotation.eulerAngles.y;
        if( localrot > 290 || localrot < 70)
        {
            //Debug.Log(rot.y);
            if (Input.GetKey(KeyCode.W))
            {
                this.transform.Translate(Vector3.forward * Time.deltaTime * speed);
                if (Input.GetKey(KeyCode.A))
                {
                    rot = (new Vector3((this.transform.rotation.eulerAngles.z),(angle * (Time.deltaTime * TurnSpeed)),(this.transform.rotation.eulerAngles.z))); // figure out why this isnt setting the rotation correctly. 
                    Debug.Log(angle);
                    angle = rot.y;
                    Debug.Log(rot.y);
                    Debug.Log(angle);
                    Debug.Log("while going forward and the A key is pressed");
                    Quaternion deltaRotation = Quaternion.Euler(rot);
                    m_Rigidbody.MoveRotation(deltaRotation);
                    Debug.Log(deltaRotation);
                    //this.transform.rotation = Quaternion.Euler(rot.x, rot.y, rot.z);
#

it dont need to be anything fancy just while im holding down the a or d key it needs to turn in that direction, and well the other direction when in reverse

tawny elkBOT
swift falcon
thin aurora
#

A properly configured editor would have correct syntax highlighting

#

Please configure it properly first to avoid unneeded mistakes that are easily handled by the editor

swift falcon
#

cool, do you have any idea why its not working though?

#

@thin aurora you still there man?

#

ive been trouble shooting this for the lest 2 days please just help me out. just throw me the correct docs or something please! i know you cant give me the answer but please just give me a hand

worthy bobcat
#

Hello i tryed to make a good Smooth Camera that you can turn with keycode right MouseButton pressed but its not Smooth and very wird can someone help me?

using UnityEngine;

public class MovementController : MonoBehaviour
{
    // The speed at which the player will move
    public float speed = 5.0f;

    // The sensitivity of the camera rotation
    public float rotationSensitivity = 10.0f;

    void Update()
    {
        // Get input from the horizontal and vertical axes (WASD keys)
        float horizontalInput = Input.GetAxis("Horizontal");
        float verticalInput = Input.GetAxis("Vertical");

        // Create a Vector3 object to store the direction we want to move
        Vector3 movementDirection = new Vector3(horizontalInput, 0, verticalInput) * speed;

        // Check if the Space key is being held down
        if (Input.GetKey(KeyCode.Space))
        {
            // Add an upward movement component to the movementDirection
            movementDirection.y += speed;
        }

        // Check if the Shift key is being held down
        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            // Subtract a downward movement component from the movementDirection
            movementDirection.y -= speed;
        }

        // Move the player in the direction we calculated
        transform.position += movementDirection * Time.deltaTime;

        // Check if the right mouse button is being held down
        if (Input.GetMouseButton(1))
        {
            // Get the mouse's x and y position
            float mouseX = Input.GetAxis("Mouse X");
            float mouseY = Input.GetAxis("Mouse Y");

            // Create a rotation vector based on the mouse input
            Vector3 rotationVector = new Vector3(mouseY, mouseX, 0) * rotationSensitivity;

            // Rotate the camera around the x and y axes based on the input
            transform.Rotate(rotationVector);
        }
    }
}
thin aurora
#

What does rot log?

knotty sun
swift falcon
swift falcon
#

its rotation is always snapping to 0

#

ill try changing the transform roation to the ridgid body rotaiton but i dont think it would fix anything.

knotty sun
swift falcon
#

but eulerAngles works for other parts of my code with checking its x and z rotation, why cant it be used for its y rotation, is it due to how its outputting? i know its a little weird but surly if it outputs it like that it knows how to convert it back to a normal angle? right?

knotty sun
#

No, that is the incorrect premiss, when converting from Quaternion to Euler you can never guarantee consistency

swift falcon
worthy bobcat
#

ok

swift falcon
knotty sun
swift falcon
knotty sun
#

because rotation is a Quaternion so rotation.y is meaningless

#

As I said start with an Euler value in your script. Modify that value as you wish during your script and convert it TO Quaternion to set rotation

swift falcon
#

sorry if this is frustrating, but i dont get how you want me to modify it.

knotty sun
#

you are getting Input values, surely that is enough to know how you modify the angles?

worthy bobcat
#

Hello i tryed to make a good Smooth Camera that you can turn with keycode right MouseButton pressed but its not Smooth and very wird can someone help me?

using UnityEngine;

public class MovementController : MonoBehaviour
{
    // The speed at which the player will move
    public float speed = 5.0f;

    // The sensitivity of the camera rotation
    public float rotationSensitivity = 10.0f;

    void Update()
    {
        // Get input from the horizontal and vertical axes (WASD keys)
        float horizontalInput = Input.GetAxis("Horizontal");
        float verticalInput = Input.GetAxis("Vertical");

        // Create a Vector3 object to store the direction we want to move
        Vector3 movementDirection = new Vector3(horizontalInput, 0, verticalInput) * speed;

        // Check if the Space key is being held down
        if (Input.GetKey(KeyCode.Space))
        {
            // Add an upward movement component to the movementDirection
            movementDirection.y += speed;
        }

        // Check if the Shift key is being held down
        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
        {
            // Subtract a downward movement component from the movementDirection
            movementDirection.y -= speed;
        }

        // Move the player in the direction we calculated
        transform.position += movementDirection * Time.deltaTime;

        // Check if the right mouse button is being held down
        if (Input.GetMouseButton(1))
        {
            // Get the mouse's x and y position
            float mouseX = Input.GetAxis("Mouse X");
            float mouseY = Input.GetAxis("Mouse Y");

            // Create a rotation vector based on the mouse input
            Vector3 rotationVector = new Vector3(mouseY, mouseX, 0) * rotationSensitivity;

            // Rotate the camera around the x and y axes based on the input
            transform.Rotate(rotationVector);
        }
    }
}
swift falcon
knotty sun
worthy bobcat
#

Bro im sorry i send this message only 2 Times now nobody is helping me. If you find thats annoving then im sorry

swift falcon
knotty sun
worthy bobcat
#

oke

knotty sun
swift falcon
#

just tell me that so i can bloody google it

worthy bobcat
sleek bough
#

@worthy bobcat Read #📖┃code-of-conduct Don't post chat generated code. Don't spam same question over and over. And use paste sites when you do come up with a proper code to show

swift falcon
#

the modify operator?

worthy bobcat
sleek bough
knotty sun
# swift falcon are you talking about this ``` transform.rotation *= Quaternion.AngleAxis(angle,...

what I am talking about is this (sorry I got your code mixed with the other persons)

localrot = (float)Child.transform.rotation.eulerAngles.z;
        //Debug.Log(localrot);
        angle = this.transform.rotation.eulerAngles.y;
        ...
                    rot = (new Vector3((this.transform.rotation.eulerAngles.z),(angle * (Time.deltaTime * TurnSpeed)),(this.transform.rotation.eulerAngles.z))); // figure out why this isnt setting the rotation correctly. 

Instead of reading the eulerAngles read them once in Start and then use them as the basis for all your calculations and keep them updated with the current state

swift falcon
#

well i mean i got past that issue, ive gotten it to be set, its just not sticking now.

leaden ice
#

you should not be poking around in the individual xyzw fields of Quaternion

swift falcon
knotty sun
leaden ice
#

Why are you rotating around the y axis in 2D, is that on purpose?

swift falcon
leaden ice
#

Why does it seem like you're using a Rigidbody2D?

#

Since MoveRotation is taking only a float here

swift falcon
#

im not.

leaden ice
#

Oh nevermind misread a little

leaden ice
# swift falcon

anyway didn't you just answer your own question with this screenshot?

leaden ice
#

really though it would be like:

Vector3 forward = rb.rotation * Vector3.forward;
float yAngle = Mathf.Atan2(forward.z, forward.x) * Mathf.Rad2Deg;```
swift falcon
#

you talking to me about this one?

swift falcon
knotty sun
leaden ice
#

"Why isn't this cat a dog???"

#

it just isn't

#

it was never intended to be

swift falcon
swift falcon
#

ight ok,

knotty sun
#

which is why we NEVER read Quaternions we ONLY write them

swift falcon
#

how should i go about this then? rewrite the turning code?

#

completely?

knotty sun
swift falcon
knotty sun
#

this really is a rabbit hole you should never have gone down

swift falcon
knotty sun
tawny elkBOT
#

:teacher: Unity Learn ↗

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

swift falcon
leaden ice
#

no because you're still looking at Quaternion.y

knotty sun
leaden ice
#

It's really not clear why you need that line at all

swift falcon
#

no no forget that just angle = (angle - (time.deltatime * turnspeed));

#

angle just being a float.

knotty sun
#

honestly people can spend weeks if not months writing and fine tuning code like this, I really suggest you find something on learn which kinda does what you want and go from there. It's the path of least pain

swift falcon
#

yes its useing wheelcolliders.

knotty sun
knotty sun
#

take it in very small steps. Try to get just one wheel working then extrapolate from there

swift falcon
#

i just got it working

#

GOD DAM IT !!

knotty sun
#

I can almost guarantee that that will fuck up during game testing

swift falcon
#

honestly i dont really care its for a college fmp, it only needs to work once XD

knotty sun
#

rofl

#

don't blame me if your wheels fall off and your car gets towed by the police.

knotty sun
#

anyway, if good enough is good enough, go for it

swift falcon
gentle pawn
swift falcon
gentle pawn
#

this is the way

swift falcon
heady iris
#

(it really should have just been called Rotation)

#

You don't need to understand quaternion math to use rotations

#

just like you don't need to understand matrix multiplication to use transform.TransformPoint

livid loom
#

Problem #1 Need help please something is not working right with an instantiated prefab it is causing particles to not look right which are a different prefab even.

Problem #2 It's causing lag as well I am guessing it's the performance issue that is causing problem #1 if someone can DM or thread and help thanks.

I am trying to create a card that spawns a unit on a tile.

stuck forum
#

i need help with code monkey's video about a* if anyone has seen it https://www.youtube.com/watch?v=alU04hvz6L4

✅ Get the Project files and Utilities at https://unitycodemonkey.com/video.php?v=alU04hvz6L4
🌍 Get my C# Complete Course! https://cmonkey.co/csharpcourse
🎮 Play my Steam game! https://cmonkey.co/dinkyguardians
❤️ Watch my FREE Complete Courses https://www.youtube.com/watch?v=oZCbmB6opxY
🌍 Get my Complete Courses! ✅ https://unitycodemonkey.com/co...

▶ Play video
#

to whoever has seen it, what does he do with the PathNode pathNode variable in the first for loop? it seems like he is just adding some values to each node for each cell but then he does nothing to the said nodes later? at least for the local pathNode variable

livid loom
#

Oh go by your game preview in the editor resolution I usually put my UI scaler at 0.25 so it is biased towards width over height but adjust according to needs really there. So I set both editor window and game preview window equal so they are about square approx.

#

You can get current preview resolution from the stats in the upper right corner of the game window.

leaden ice
#

Did you properly anchor your UI elements?
This is a #📲┃ui-ux question not code

formal otter
#

Ahh Appologies

#

I didn't see this channel.

#

I'll move my question over.

unique delta
#

I don t know where to ask but made a github colaborate project and my friend can t open the project because ArtifacDb is locked somone has a solve?

leaden ice
#

I recommend deleting the respository and remaking it with an appropriate .gitignore file

wind meteor
#

Apparently my Unity thinks 1*3 is infinity

unique delta
#

from where?

#

i found one online for unity and that was the only one that i had in the project

unique delta
#

i already had this one in the project when uploaded

leaden ice
#

Did your repo contain the Library folder?

#

Check

#

if it did, you had already committed it before adding the gitignore file

unique delta
leaden ice
#

Can we verify the library folder is actually the issue here?

leaden ice
#

repository

#

the thing you store and retrieve with git

#

the thing that your project is saved in

wind meteor
# wind meteor Apparently my Unity thinks 1*3 is infinity

I wanted to calculate the density of an object, so I had to calculate the volume, which I did by using volume = colComp.size.x * colComp.size.y * colComp.size.z;, and fir tge mass I just used rb.mass.
If I Debug.Log(rb.mass) it's 3, like it should be,
if I Debug.Log(volume) it's 1, like it should be,
YET if I Debug.Log(density), which I calculated with density = rb.mass / volume;, it's, and I quote my Debug panel, "Infinity".
Why?

wind meteor
unique delta
leaden ice
unique delta
#

i m pretty sure

leaden ice
#

if it's there, I already suggested how to fix it

#

don't be "pretty sure"

#

look and be 100% sure

unique delta
#

i m 100000% sure

leaden ice
unique delta
#

thanks

mellow sigil
leaden ice
mellow sigil
#

You calculate density before setting volume

leaden ice
#

You're not setting density until you run the CalculateBuuoyancy function

wind meteor
leaden ice
#

or rather yeah

#

you're setting volume AFTER

wind meteor
#

Dammmmnnnn and it took me this long to realize.

#

Yeah it works now thanks

leaden ice
# wind meteor

By the way there's a cheeky/hacky way of retrieving the automatically calculated volume and density of a Rigidbody. You can do this:

float originalMass = rb.mass;
rb.SetDensity(1); // If we set density to 1...
float volume = rb.mass; // Then the mass that got set will equal the volume of all the colliders!
float density = volume / originalMass; // Here's our calculated density

// Finally, set the mass back to normal!
rb.mass = originalMass;```
#

(assuming that's what you were trying to do)

swift falcon
#

I dont know whats the problem is

leaden ice
#

The first problem you have, is your IDE is not configured

#

you haven't set your tools up properly for working with Unity yet. Get it configured

#

!ide

tawny elkBOT
wind meteor
# swift falcon I dont know whats the problem is

Uhm Idk if that's what PraetorBlue meant too but you also have to create the roadSpawner variable first by putting RoadSpawner roadspawner; before the start function, because you have to define the class/type of a variable when creating it, like int x = 5; and then you can use x

#

Also you have to put () after SpawnTriggerEntered to turn it into SpawnTriggerEntered()

leaden ice
#

Yes all that but there's no point in fixing the code until they configure their IDE first

#

it will be a waste of time.

wind meteor
#

But yeah setting up your IDE helps with that tremendously

wind meteor
rare phoenix
#

I made a very big quad procedurally and this material won't render on it, but the base material does. Is there a setting there that I missed to make it work?

naive swallow
rare phoenix
#

Hey! Yes, here's the object in the inspector. When I change the rendering mode on the material like opaque I can see my quad. But the goal is to have the pattern I assigned in albedo display and it doesn't do that 😦 Also, the material works fine on other Meshes like the basic plane

#

Oh I think my procedural quad is missing UVs on the vertices and that's why all that is "rendering" is the transparent part...

mild spindle
#

I don't get what's wrong

somber nacelle
#

you cannot refer to an animation clip in the animator like that. the animator does not support indexing, especially not indexing with a string. you should take a look at the Animator docs

naive swallow
inner moss
#

How can I make a box collider not attached to the body of the Game Object they're the child of ?

#

This messes up one of my key mechanics

somber nacelle
#

well that's not really a code question. but if you don't want it attached to the parent gameobject, then why is it a child of that object?

inner moss
#

Bc it needs to move with it

leaden ice
#

what does the word "Attached" mean to you?

inner moss
#

Trust me, I've tried a bunch of stuff

#

Ok

#

So basically

#

It's the Box collider of the GO with the tag "Gun"

#

But if it touches an object, it acts as if it was "Player" that did

somber nacelle
#

yes, that is what happens when a collider is a child of a rigidbody, it becomes part of that rigidbody's compound collider

#

what is the purpose of this collider

inner moss
#

So how could I make that not happen while keeping it as a child ?

somber nacelle
#

because i'm gonna go ahead and guess this collider should actually not exist at all and should just be a physics query instead

inner moss
#

I use it like a raycast

#

Since I can't make that work for the life of me

#

(my code is way too messed up, holds with hopes and dreams)

leaden ice
#

maybe just make the raycast work properly

#

and get rid of this jankness

#

maybe ask for help with your raycast

inner moss
#

I would have done so if I could lmao

somber nacelle
inner moss
#

(Basically it's become messed up since another mechanic is really jank)

leaden ice
#

the real answer is to get rid of the collider and fix raycasting properly

inner moss
#

Is there, like, no way to fix that without having to rework all of my code

#

That's probably a better way to ask it, sorry

leaden ice
#

Honestly it sounds like there wouldn't be that much code to rework

#

like 20 lines at most

inner moss
#

I use VS

#

So it's another world lmao

leaden ice
#

how is that relevant?

#

oh

#

visual scripting

inner moss
#

yup

leaden ice
#

well, that's a whole nother conversation but like

#

that's a hole you dug yourself 😆

inner moss
#

Yeah I know...

leaden ice
#

either way I think you should take a stand against yourself

#

and for once

#

instead of taking the janky path-of-least-effort

#

go back and fix it for real

inner moss
#

I'd have to start from scratch and I'm in a jam

#

I would if I could

inner moss
#

(Maybe I should explain better, I use that collider like I'd use a raycast to easily have other GO detect when I shoot using it)

#

(But some objects, i need them not to interact if I shoot them)

#

(Taht's why it's such a mess)

#

OH WAIT I HAVE A SOLUTION

#

Super janky and dodging the problem, but it should work

#

(Creating a bool that activates while I shoot that deactivates the interaction)

somber nacelle
#

a raycast or boxcast with a layermask to filter out objects you don't want to "shoot" would be much better here and wouldn't require a bunch of janky workarounds

inner moss
#

It would also require to rework pretty much all of my gun movement mechanics sadly

#

And I'm in a jam so I can't

#

Tho I'll do that next time I encounter the issue

lean sail
#

Surely you arent that far into any solution where you cannot just make a physics cast

leaden ice
somber nacelle
inner moss
#

Okay I'll explain but it'll be super long

#

So basically I'm creating a 2D game where you move your gun around you with the left stick

#

But I'm too dumb to make stuff properly

#

So I coded it to work with a pointer that moves super fast in a clamped area, put an empty that looks at it at all times and then puttin the gun as a child of it

#

But that's really jank and anything more done to it would probably make it crumble bc of how weirdly it messed the z axis

#

So a raycast just goes nowhere

#

And messes a lot of stuff

#

Which the collider doesn't

#

And it was also easier to implement for interactible stuff like buttons

#

So I went with that

leaden ice
#

Sounds like a nightmare but have fun

inner moss
#

it is 🥲

somber nacelle
inner moss
#

Also some other stuff added to it that I barely understand

#

But yeah that's basically it

#

The gun is holding together with shit and glue

#

(tho I use Visual Scripting so I'm not uusing that but probably something similar)

tight goblet
#

Hey there pretty people! I used the SimpleWebServer to test a WebGL build locally on localhost:8017, how can I stop the server from running?

leaden ice
#

Sounds like a SimpleWebServer question

tight goblet
leaden ice
#

Unity is more or less just an artifact on the web page

#

Like an image

mild spindle
#

hello i'm trying to make my 2d character do an animation (A) when a key is pressed then come back to the idle animation when the animation (A) finish

naive swallow
swift falcon
#

help

public AudioSource passosAudioSource; // Referência ao AudioSource para os passos
public AudioClip[] passosAudioClip; // Array de clips de áudio para passos

void Passos()
{
if (passosAudioClip.Length > 0 && passosAudioSource != null)
{
passosAudioSource.PlayOneShot(passosAudioClip[Random.Range(0, passosAudioClip.Length)]);
}
else
{
Debug.LogWarning("ReproduzirPassos: AudioSource ou AudioClip não foram atribuídos corretamente.");
}
}

naive swallow
green wharf
#

I created multiple cameras in unity and I want to make a car simulation game but I'm facing this error:
d3d11 failed to create rendertexture (270 x 152 fmt 27 aa 1), error 0x8007000e
There is no ss of this error because my computer shuts down when I get this error

naive swallow
# mild spindle

That "Flap -> Falling" transition looks like you've put the falling animation as soon as possible. It should play after the flap animation is done. Drag it to the end of the clip

rugged storm
#

yo how do i start a set of coroutines and wait for them all to finish, the number is not always consistent, I'm running the same coroutine each item in a list.

naive swallow
#

There should be one falling after flap finishes

#

there might be a smidge of overlap

#

but there should be only one at the end

naive swallow
rugged storm
#

im running multiple Coroutines from this coroutine

    private IEnumerator ClearBlocks(List<Block> blocks)
    {
        foreach (Block block in blocks)
        {
            //run a coutuetine "ClearBlock(Block block)" on each block only continue after all are done 
        }
        yield break;
    }```
mild spindle
naive swallow
#

yes

heady iris
#

Actually...

rugged storm
#

actually nevermind i realized a better way to do this

heady iris
#

ah, no, you can't ask an IEnumerator if it's done

#

you have to call MoveNext

rugged storm
#

i just put the logic from ClearBlock into a Loop foreach loop in a while loop;

heady iris
#

the only problem is that this will run sequentially, not all at once

rugged storm
#
    private IEnumerator ClearBlocks(List<Block> blocks)
    {
        const float timeOfClear = 0.3f;
        float finish = Time.deltaTime + timeOfClear;
        while (Time.deltaTime < finish && blocks[0].sr.color != Color.white)
        {
            foreach (Block block in blocks)
            {
                block.sr.color += Color.white * 0.8f;
            }
            yield return null;
        }

        yield break;
    }```
#

like this i mean

heady iris
#

ah, this doesn't do what you think it does

#

Time.deltaTime is the time the last frame took

rugged storm
#

Oh oops

#

ty for catching that

heady iris
#

There is a way to ask for the realtime since startup

#

which changes throughout a single frame

rugged storm
#

should be Time.time right?

heady iris
#

Localization uses that to avoid spending too long per frame on a cleanup job

#

no, that's also constant during a frame

#

Time.time depends on the timescale and won't go up if unity is frozen for a while

mild spindle
rugged storm
#

oh thats good actually im only looking for scaled time here

heady iris
#

(and Time.unscaledTime still isn't the literal amount of time that has passed in the real world)

heady iris
#

if so, you care about real-world time

rugged storm
#

oh no basically its just a block matching game this is the animation for clearing a group of blocks

heady iris
#

ah, I see

rugged storm
#

if the player pauses it should pause the effect

heady iris
#

and oops, I just saw the yield return null at the bottom. So it's one iteration per frame

rugged storm
#

yeah

mild spindle
heady iris
#

however the deltaTime part is still off, yeah

#

So you do want Time.time after all :p

rugged storm
#

yeah

#
    private IEnumerator ClearBlock(Block block)
    {
        const float timeOfClear = 0.3f;
        float finish = Time.time + timeOfClear;
        while (Time.time < finish && block.sr.color != Color.white)
        {
            block.sr.color += Color.white * 0.8f;
            yield return null;
        }

        RemoveBlock(block);

        yield break;
    }```
updated code
heady iris
#

I'm pretty sure this will shoot past Color.white and run for the full 0.3 seconds

#

Do you want the effect to fade the block to white over 0.3 seconds?

rugged storm
#

yeah or cap at white, oh can color values go beyond 1,1,1,1?

heady iris
#

Color uses floats

rugged storm
#

Oh

heady iris
#

You can do this:

rugged storm
#

color is basically just a vector4?

heady iris
#

yep

heady iris
# heady iris You can do this:
Color startColor = block.sr.color;
Color endColor = Color.white;

float startTime = Time.time;
float endTime = Time.time + timeOfClear;

while (Time.time < endTime) {
  float progress = Mathf.InverseLerp(startTime, endTime, Time.time);
  block.sr.color = Color.Lerp(startColor, endColor, progress);
  yield return null;
}
#

InverseLerp tells you how far along you are between two values

#

And then Lerp gives you a blend of two values

rugged storm
#

Theres a color lerp??? tysm

heady iris
#

yeah, there's a bunch of em

#

took me a bit to find out :p

heady iris
#

but you're destroying the block right after anyway, so it doesn't really matter

rugged storm
# rugged storm ```java private IEnumerator ClearBlock(Block block) { const floa...

oh wait i pasted the wrong code here this was clearBlock Singular
but i adapted it to work in clearblockes all at the same time i think,

    private IEnumerator ClearBlocks(List<Block> blocks)
    {
        
        const float timeOfClear = 0.3f;
        Color startColor = blocks[0].sr.color;
        Color endColor = Color.white;
        float startTime = Time.time;
        float endTime = Time.time + timeOfClear;
        while (Time.time < endTime)
        {
            float progress = Mathf.InverseLerp(startTime, endTime, Time.time);
            foreach(Block block in blocks)
            {
                block.sr.color = Color.Lerp(startColor, endColor, progress);
            }
            yield return null;
        }

        foreach (Block block in blocks)
        {
            RemoveBlock(block);
        }

        yield break;
    }```
(all blocks are the same color so i get crab the startColor from the first in list
heady iris
worldly hull
#

currently my team has 5000+ debug log statement inside the project, this is quite bad as we dont have any config to these debug logs, they will still execute during runtime when our app goes into production stage

we also cannot delete them directly as we need them during development stage, any good idea?

#

my idea is to override the original debug log code tho, but i need to check whether the debug log function is hidden by unity or not

#

maybe add
#if unity-editor
#else
to it

#

ok this is bad you cant override it

#

annnd it seems u cant modify it from assembly as well

#

what my debug log(error) needs

  • identical function like original debug

  • only can execute on editor

  • all built app cannot use it

soft shard
# worldly hull currently my team has 5000+ debug log statement inside the project, this is quit...

You can use the Logger to disable logs when you make a build, enable them when your testing in Unity, maybe you can use preprocessors to determine if your in the editor as you have, to toggle .logEnabled: https://docs.unity3d.com/ScriptReference/Logger.html (you may have to scroll down on that page)
Additionally, you can hook into the Debug.Log event and handle the logging yourself: https://docs.unity3d.com/ScriptReference/Application.LogCallback.html, or if youd rather have more control over it, albeit more work on your part, you could build a wrapper, and do a refactor (in VS, Ctrl + R twice), for all Debug.Logs to use your wrapper instead

swift falcon
#

pretty new to unity, trying to use OnAfterDeserialize() on an inventory scriptable object to update the inventory display when the item changes. I can't directly access the item's sprite during serialization so I don't know how i can update it whenever an item is changed

#

the items are scriptable objects as well

worldly hull
#

wait wrapper is better

#

my game manager will not destroy and will last thruout the whole game process

#

i gonna do the wrapper there

heady iris
#

OnAfterDeserialize will only run when the object is deserialized -- as part of its creation

#

If you want to be able to notify things when the sprite changes, perhaps you want to use an event

#

It sounds kind of weird to be modifying a SO asset at runtime though. Can you explain more about what you're doing here?

swift falcon
#

here's the exact error i get, UnityException: get_rect is not allowed to be called during serialization, call it from OnEnable instead. Called from ScriptableObject 'InventoryObject'.

heady iris
#

this feels like an XY problem

swift falcon
#

not trying to edit the scriptable object, just get it's sprite component to update the inventory cell to the item's sprite

heady iris
#

why are you trying to do this in OnAfterDeserialize?

#

just get the sprite out in the OnEnable method of the inventory cell

swift falcon
#

that'll probably do it lmao

#

pretty new to this

#

especially the serialization stuff

heady iris
#

there's nothing serialization-related here

swift falcon
#

its using iserializationcallback reciever

heady iris
#

well, there's no reason for it to be involved :p

#

ISerializationCallbackReceiver is there for situations where you want to set up data that Unity can't handle by itself

swift falcon
#

and those embedded functions are giving me the issues

heady iris
#

The example creates a dictionary from two lists

latent latch
#

I mostly use the interface for c# classes because you need mono for OnValidate()

heady iris
#

Unity can't serialize dictionaries -- just lists. The example uses the callback receiver to glue them together right after the lists are set up by Unity

#

to "serialize" is to turn an object into data

#

and then you "deserialize" the data back into an object

#

You aren't doing this -- you're just grabbing a sprite from a scriptable object

bronze fog
#

who fucks with it

worldly hull
#

u know just like using it as Debug.Log

quartz nova
#

Why would you want to do this?

worldly hull
#

ok u cant lol

worldly hull
#

which is awful

#

so i want to do something , more like an override to it, to make the Debug.log only runs on editor mode, but not in any built apps

#

annnnnd ofc u cant modify the source code directly right?

debug log is also a static class, u cant override it directly

lean sail
#

ive sent you the literal code for it

worldly hull
#

ok

#

guess u can now lol

#

ty

lean sail
#

its not about modifying it, but if you wanted to create your own then just copy what you want and implement whatever else on top

faint hornet
#

Hey Everyone!

Need help solving a problem. My goal is to have the camera zoom in or out depending on how far away the player is to a centered position.

i want to lerp between 10 and 15. min being closest to center, and max being furthest posible away from center.

the problem is i don't know how to translate the distance between two vector3 positions into a float.

any help?

heady iris
#

isn't the distance between two vector3 positions a float

fluid locust
#

how do i collaborate on a unity project on version 2023.3.28f1

lean sail
fluid locust
#

ok

#

thanks

worldly hull
#

ok just wanna share my solution after all of this

public class LogOnDebug : ILogHandler
{
  public void LogFormat(LogType logType, UnityEngine.Object context, string format, params object[] args)
  {
    Debug.unityLogger.logHandler.LogFormat(logType, context, format, args);
  }

  public void LogException(Exception exception, UnityEngine.Object context)
  {
    Debug.unityLogger.LogException(exception, context);
  }
}```

im now making a new custom logger function which will replace debug.log/debug.logerror , we dont have warning so we ignore it lol

i gonna replace all existing debug.log to this custom logger
#

i have a game manager that will guarantee to be instantiated and initialized before everything else

  public Logger LogOnDebug = new Logger(new LogOnDebug());```
#

annnd ofc i will keep modifying my logger script

#

ok

heady iris
#

You may be interested in ConditionalAttribute

#

It lets you remove a method call entirely if a preprocessor directive isn’t set

worldly hull
somber nacelle
worldly hull
#

sounds better 👍

exotic aspen
#

Howdy folks. I'm trying to improve my animation state machine for an RTS game and could use some input if anyone has time. Every 100ms each AI unit's update call determines which animation to play based on its current state. For most cases this is a single call to "fire" or "die" that in the animation controller transition automatically back to an idle state, or hang on the last frame, or loop. And that all works fine. Where I'm having issues is the walking animations. If walking, then every 100ms the routine calculates the direction of movement and calls myAnimator.Play("walk direction"); And it works reasonable well, except it will call this repeatedly and so the animation's frames restart halfway through depending on various factors. I don't see an easy way to only play it again if the animation is not the one intended.

#

I should mention the walking animations are all looped, hence why it doesn't need to be played repeatedly.

worldly hull
#
  [System.Diagnostics.Conditional("UNITY_EDITOR")]
  public void Log(object message)
  {
    Debug.unityLogger.Log(LogType.Log, message);
  }```
#

lol ok thats not 5000+ debug logs

#

still hurts tho

cosmic rain
exotic aspen
#

:nod: That was where I was leaning. Didn't know if perhaps the animation system had a flag for "don't let this play over itself" sort of thing.

faint hornet
#

can someone please tell me how to debug this. my game freezes when changing song ( entering circle trigger ) the first time and never again ( except for super rare occurance. it happens at run time and happens when i deploy full build.

lean sail
exotic aspen
faint hornet
#

@exotic aspen @lean sail this is what i found in profiler

exotic aspen
#

Yeah that looks like something loading audio related.

faint hornet
#

@exotic aspen awesome. so it's not my code. thank god. i was about to panic with the amount of debugging i'd have to do.

exotic aspen
#

Yeah check out that link and see if it works for you.

faint hornet
#

@exotic aspen fixed! thank you!

somber nacelle
#

interfaces are not inheritance. the only methods on that interface are LogException and LogFormat so you aren't inheriting anything, and you have to implement those. anything else is implemented by you

worldly hull
#

its weird then

#

the code you saw above is all of the "LogOnDebug"

somber nacelle
#

are you sure the LogOnDebug object you are calling LogError on is that LogOnDebug class and not perhaps some other class that implements ILogger since that is the interface you would use for logging?

worldly hull
#

yo wait

#

ok im blind

worldly hull
#

i used Logger to instantiate it lol

eternal osprey
#

Someon who wanna make a cool 2d game with me?

somber nacelle
tawny elkBOT
eternal osprey
scarlet viper
#

how do I reference an Editor script from another script?

somber nacelle
#

can you explain what exactly you are trying to achieve?

thin aurora
pine condor
#

you can use GetComponent<script>() on the object with the script for most cases

somber nacelle
#

not for an editor script

thin aurora
#

Again, depends heavily on the context

plucky inlet