#archived-code-general

1 messages ยท Page 89 of 1

south heron
#

When creating a projectile system I came through the following point: lets say I have slow moving projectiles in my RTS game, server and client will spawn their own gameobject with a particles system on them. Projectiles are pooled, because reasons. Now I have let's say 200 different projectiles in terms of particle system. Is it a good practice to have 1 prefrab gameobject with 200 different particles system on them and activate the right one or make a pool for every projectile (go, ps combo)? Can unity handle that?

heady iris
#

it sounds like there is some kind of mix-up, because if all of these things are indeed non-null, then there should be no error

rugged storm
#

also btw reminder this only started when make all the tiles children

heady iris
#

an object in the list being null would not cause an exception to be thrown from the foreach itself

#

perhaps from an expression in its body, sure

#

(well, an object in the dictionary's Values property, whatever that is)

rugged storm
#

and just made sure, commenting out the stuff that makes it a child does fix it... so i think the issue has something to do with that...

heady iris
#

have you done this by explicitly logging them before trying to use them?

#

if not, then go do that.

rugged storm
#

wym? like lookin at GridManager.Instace.tiles in a breakpoint on the foreachloop?

heady iris
#

Just log it.

#

see if it is null

#

before you enter the loop

rugged storm
#

im super new to unity I'm lost on the terminology im sorry

heady iris
#

from what you have told me, the foreach statement itself is throwing an exception

#

Debug.Log(GridManager.Instance);

rugged storm
#

Oh okay

heady iris
#

and the same for the tiles field

#

if one of those spits out an empty log entry, then that thing is null

rugged storm
#

Oh the tiles field is returning null then.

heady iris
#

well, there you go!

leaden ice
heady iris
#

sounds like you didn't assign it

#

the solution to an NRE is always, always, always to check all of the things you're dereferencing on the line that threw the error

rugged storm
#

okay issue still is i dont get why cuz its public, it only stops working when i add this line "var grid = Instantiate(gameObject).transform;" even if I dont make the times children of it

heady iris
#

show your code.

#

i can't guess

#

(the whole thing, in a paste)

rugged storm
#

kk

heady iris
#

that's the vibe i'm getting here

rugged storm
leaden ice
rugged storm
heady iris
#

I'm reluctant to use the address 'cos I might decide to rename the individual assets

rugged storm
#

wait could it be becuase the empty takes the name of the script?

heady iris
#

RuntimeKey is...object

#

mysterious

rugged storm
#

when i do cs var grid = Instantiate(gameObject).transform;

heady iris
rugged storm
#

OHHHH wait,

heady iris
#

it won't have the dictionary on it

rugged storm
#

yeah i just realized that lmao

#

i mean to just make a new empty there

#

not a copy of the gameobject that scene is attached to

heady iris
#

ah, that would do it

#

you'd get an NRE from the copy as it tries to function (without being set up correctly, presumably)

rugged storm
#

okay so final thing, how do you instantiate an new empty?

#

actually even easier i could just make this script the parent...

heady iris
#

just new GameObject();

#

you're not allowed to construct a mono behaviour...but this isn't a mono behaviour (:

rugged storm
#

What does that mean?

heady iris
#

you can't do something like

#

var rb = new Rigidbody();

#

that is valid C#, but will fail at runtime

#

however, that is the appropriate way to create a new empty game object

#
var obj = new GameObject();
heady iris
rugged storm
#

Ah okay I get what you mean

#

Also most of the time I see people asking about like how to fix errors and stuff so I assumed not but would you also ask about like general tips in this chat? Like is there any way to make the two pastes I sent better, cuz I imagine they are pretty messy given I made them half following a tutorial while also trying to do my own thing with my very limited unity knowledge

patent wadi
#

what is xr?

heady iris
patent wadi
heady iris
#

XR is allegedly an acronym

#

it covers stuff like VR (virtual reality) and AR (augmented reality)

late lion
heady iris
#

ah, that make more sense

#

i was a little curious where the xr variable was meant to be coming from

patent wadi
late lion
patent wadi
#

what do i replace cameraData.isStereoEnabled with?

late lion
#

cameraData.xrRendering

#

But it might depend on which URP version you're using

potent sleet
#

2022 is not a URP version

#

2022 is 14.0 +

heady iris
#

It does give you a good idea of the version, at least :p

heady iris
#

alas

daring cove
#

Hey, to check if a point is in a cone?

radius is the radius of the cone.
maxDistance is the length of the cone.

a is the origin of the cone
b is the position of point in the cone

b is obtained from a raycast thus should always be in the range of maxDistance.

This angle doesn't seem to calculated properly.


Vector3 direction = (a.transform.position-b.transform.position).normalized;

float angle = Mathf.Abs(Vector3.Angle(a.transform.forward, direction)-180);

if(angle > radius) return false;

// in cone
return true;
heady iris
#

you're on the right track, but you wouldn't compare that angle against the radius

#

compute the angle to the edge of the base

#

I guess you could completely avoid trig by making a vector to a point on the base, then computing the angle between that and the center axis

leaden ice
heady iris
leaden ice
#

I'm assuming they just have the "tip" point of the cone (A) and an angle

#

like a typical "AI guard line of sight" situation

#

Not the standard mathematical definition of a cone

#

They did say radius but then compared that to an angle so not sure

#

i.e. like this

#

they have the smiley face (A) and the red point (B) and some angle

daring cove
#

This is in 3D

leaden ice
#

same difference

daring cove
#

alright

#

The angle should be the angle from the base of the cone to the point

leaden ice
#

wdym by "base of the cone"?

#

the flat part?

#

If so what does an angle from there to the point even mean?

daring cove
#

the base would be the smiley face

daring cove
#

Why do you not normalize the direction?

leaden ice
#

there's no need to

#

Vector3.Angle doesn't care about the magnitude of the vector

#

It might even normalize the vector internally - in which case why waste the CPU cycles doing it twice?

lean sail
#

apparently angle does normalize both vectors given

drifting crest
#

Im tryna make clone of hill climb racing but the tire is sometimes going inside the ground I am using an edge collider on Ground , I tried to tweak the damping ratio and frequency of wheel joint component but no clue

leaden ice
daring cove
drifting crest
potent sleet
#

Ah I've never used that one . hmm are you following a tutorial or are you writing your own script . Can you show it ?

drifting crest
# potent sleet Ah I've never used that one . hmm are you following a tutorial or are you writin...

Yeash , im following a tutorial https://youtu.be/E8lR59Yb2A0 this one by @tranquil ember

Join our Discord Community! - https://discord.com/invite/aHjTSBz3jH
Show your Support & Get Exclusive Benefits on Patreon! - https://www.patreon.com/sasquatchbgames
Wishlist Veil of Maia! - https://store.steampowered.com/app/1948230/Veil_of_Maia/

Make a 2D racing game like Hill Climb Racing with this quick Unity tutorial. We'll even manage to ...

โ–ถ Play video
potent sleet
tawny elkBOT
#
Posting code

๐Ÿ“ƒ Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

๐Ÿ“ƒ Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

drifting crest
#
    [SerializeField] private Rigidbody2D tire2 = default;
    [SerializeField] private Rigidbody2D carRb = default;
    [SerializeField] private float carSpeed = default;
    [SerializeField] private float rotationSpeed = default;
    private float _moveinput;

    private void Update()
    {
        _moveinput = Input.GetAxisRaw("Horizontal");

        if(Input.GetKey(KeyCode.R))
        {
            SceneManager.LoadScene("MainGame");
        }
    }

    private void FixedUpdate()
    {
        tire1.AddTorque(-_moveinput * carSpeed * Time.fixedDeltaTime);
        tire2.AddTorque(-_moveinput * carSpeed * Time.fixedDeltaTime);
        carRb.AddTorque(_moveinput * rotationSpeed * Time.fixedDeltaTime);
    }```
#

That's the code for driving car

leaden ice
#

Not sure about the wheel thing - but multipliyinh the torque by fixedDeltaTime is wrong

leaden ice
#

because it doesn't make any sense

#

It's basically the same as arbitrarily putting / 50 there

drifting crest
leaden ice
#

no

#

also speed is a poor name for those variables since they represent a torque amount, not a speed.

lean sail
#

i assume your speeds were set pretty high because of that

leaden ice
#

yep - remove the fixedDeltaTime and reduce the speed variables by a factor of 50

solemn raven
#

hi,
i'm trying to learn shader's code.
i have a question why do everyone writes the first parameter of each variable a string of description , do i need to do that in everyshader i have ?
example: _StencilComp ("Stencil Comparison", Float) = 16 , do i need to write "Stencil Comparison" as a first parameter for the float ???

#

cant i just do it normally like float _StencilComp = 16 ?

simple egret
tranquil ember
# drifting crest Im tryna make clone of hill climb racing but the tire is sometimes going inside ...

Two things you could try:

1 - change collision detection on the wheels from discrete to continuous. Not sure if that'll do it but it's worth a try.

2 - move the initial position of the wheels WAY further down than what looks natural. Take a look at some hill climb racing screenshots to see what I mean. Your car looks way too close to the ground. (Don't forget to update the anchor points when you adjust the wheel position)

potent sleet
glossy basin
#

Hello there, How can read the info of this column from the profiler? It seems like profile counter contains my answer, but I dont know which profiler category this belongs to and its counter name

#

is it even possible?

#

I would like to use it for debugging and displaying it on my screen

glossy basin
#

I have used the get category method but fun thing is that the values it returns can not be accessed / dont appear when looking for that manually

potent sleet
#

is there a reason you wanna show GC at the player ?

soft shard
#

Im looking for some ideas for implementing this kind of system - in my FPS game, I have a script on the camera to detect objects with a IInteractable interface, but I want to add a system where if a player "dies" (reaches 0 HP) they instead get incapacitated and can then be interacted with in some way (similar to Apex or Fortnite, etc), im thinking of putting the interface on the player controller but then I have to check their HP every time a player looks at someone, and I dont like the idea that the interactor on the camera has to determine the condition for interacting, not every interactable has health, but they all DoSomething() - im wondering if there is maybe a better approach, would a new script using the interface, that is only enabled when the player is "dead" be the best option for this?

glossy basin
potent sleet
#

like a key for kvp or something

glossy basin
#

Also I debugged all available categories and it displays categorioes that I cant even get

potent sleet
#

I never dabbled on this yet so I cannot provide much help sowy :

wide mural
#

i've built my game, works fine in editor and no build error but for some reason the sound effect mixer is totally missing (no sound effects) and i have some blur effect and particle effect not showing at all from the build..? idk how to figure out with no errors

glossy basin
dusky heath
#

Hi everyone. I'm currently working on UI navigation. I've been using custom UI solutions with EventSystem interfaces. How can I make my own solutions compatible with the Unity's navigation system?

thin aurora
tawny elkBOT
#
๐Ÿ’ก IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

โ€ข Visual Studio (Installed via Unity Hub)
โ€ข Visual Studio (Installed manually)

โ€ข VS Code*
โ€ข JetBrains Rider
โ€ข Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

dusky heath
#

I also shared the full code in pastebin.

round willow
#

Hey, not entirely sure if this is the right channel for this, but...it feels like GPU instancing doesn't work.

leaden ice
round willow
#

What's the best channel to ask about this kind of stuff?

#

Ok, thanks

leaden ice
tardy trail
#

Does Anyone Know Playfab REALLY Well

#

I have this script and my item ids are exactly correct the playfablogin catalog is Catalog 1 which is the catalog name and when i press it it says Error: Invalid Input Parameters

tawny elkBOT
#
Posting code

๐Ÿ“ƒ Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

๐Ÿ“ƒ Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

rotund burrow
#

I want to create cheap visuals for debugging that I can see in play mode and later replace. Should i use mesh generation?

leaden ice
#

there's always Gizmos

#

or just using basic cubes and stuff

undone prism
#

yo i have a problem with unity where you have a gameobject in a dontdestroy but when you get back to menu you get 2 of them. is there a way to say that i dont want to spawn another one while ingame?

leaden ice
#

it's very common

#

(that's why it's called the singleton pattern - you only want one of them at a time)

undone prism
#

aight aight tnx

tardy trail
#

what abt my problem why no one help me

leaden ice
#

Maybe nobody knows playfab well

tardy trail
#

oh

#

i just really need help

#

i have a game on the quest 2 store and when u uninstall you lose everything and it rly annoys ppl

potent sleet
#

ur better off asking on the playfab discord

knotty sun
heady iris
#

wasn't the worst thing in the world!

unreal valley
#

Is there an equivalent to Scriptable Objects in C#? Like making an Abstract Class or something? I need some help. Essentially want to do the same thing as a SO. Where I can declare some Variables and then set them for each new one made. But im stuck.

Im making a JobBase and then making the actual Jobs inherit from Base. But idk what im doing I guess. Never comes out right.

#
public abstract class JobBase
{
    public string JobName { get; set; }
}

public class Job_Warrior : JobBase
{
    JobName = this.GetType().Name;
}
#

Basically the above, but I can't override the JobName, not sure what to do

heady iris
#

JobName is a property here, and it's not marked virtual

#

you can do something like...

#
public abstract class JobBase
{
  public virtual string JobName => "No Name Job";
}

public class JobWarrior : JobBase
{
  public override string JobName => "Warrior";
}
#

you can't assign to a field (or property) like that in the class declaration at all

#

you can provide a default value for a newly declared field, but it can't use a function call like that

unreal valley
glossy basin
#

hello there, I am using this code here Profiler.GetAllocatedMemoryForGraphicsDriver() / 1073741824.0 for retrieving the current graphics card usage of my project, however it just increases every time and doesnt decrease when I for example remove objects from the scene, is there any other line of code to get the current graphics usage?

heady iris
#

each state has a property that says how fast the player can move

#

and i just override it as eneded

heady iris
#

also, note that this is just "allocated memory"

glossy basin
heady iris
#

I dunno

#

Why are you worried about it?

glossy basin
cosmic rain
#

If we're talking about RAM, it's gonna be cleared by the GC if there are no references to the object and GC is allowed to collect it. If we're talking GPU memory, you probably need to resource that occupies the memory.
As for what you profiled, I'm not even sure if it's either of those.

glossy basin
heady iris
#

it is probably correct

#

just not precisely what you imagined

glossy basin
glossy basin
#

I imagined It would go Up and down

heady iris
#

there's gonna be a lot of slop there

glossy basin
#

depending on content

heady iris
#

i'd just sanity-check by adding a bunch of 4k textures to the scene and making sure the number goes up

glossy basin
#

but as I said using the UnityStats shows a more accurate representation, and the value never goes up as the current method im using

#

this is how my stats, on the graphics card part it uses 2GB when I am using a single texture

#

ofc it goes down when restarting the scene, but still, its quite a big number considering my texture is a texture atlas, 32 * 32

cosmic rain
#

There's more than just your textures involved in rendering. For starters, there's the render target, and there could be other intermediate resources that occupy the memory as part of the rendering process.

#

And again, I'm a bit sceptical wether GetAllocatedMemoryForGraphicsDriver() corresponds to GPU memory exactly.

heady iris
#

i do have to wonder if that number is very useful for systems that aren't sharing memory with the gpu

#

"for graphics driver" is the funny part

glossy basin
glossy basin
glossy basin
# heady iris "for graphics **driver**" is the funny part

Lmao, I will probably removed that, I have seen that some version of Minecraft that use shaders do not work on certain driver versions, so I wanted to include the driver name in case somebody faces the same issue, but since this is Unity and not Minecraft, I assume that's most likely to not happen

heady iris
#

oh no, I just mean that the function name makes me a little suspicious

cosmic rain
#

The forums seem to confirm that it corresponds to the GPU memory though.๐Ÿค”

heady iris
#

I guess it's just the allocation

#

not the exact usage

cosmic rain
#

They do mention that it's an estimate though.

glossy basin
solemn raven
#

Does the function OnValidate of the BaseMeshEffect only runs on the editor mode ?
Do i need to wrap it under #if UNITY_EDITOR ... #endif ?

glossy basin
#

Hello there, I am wondering what approach I should take for defining block stats (in a performant way), I currently have a voxel game, and the way I am defining my blocks array is by simply using an enum, and then storing their values there (i.e BlockType.Air or BlockType.Stone) (since enums are ints under the hood), now I want to implement a survival destruction system where the blocks have certain durability before breaking, so I though of rebuilding the array and instead of enums, use structs which contain the corresponding block stats, however I am not sure about how performant this could be, is there any better aproach to this?

I also though of just using a singleton or static class that contains all block data and whenever I try to destroy a block, just go to that class and get the block thougness and such. What is the best approach?

heady iris
#

not duplicating the data a few thousand times feels like the right move

leaden ice
#

If you need to add more data, a bigger struct with multiple fields seems a good way.

glossy basin
leaden ice
#

compared to what

#

everything you do in computing affects performance somewhat

glossy basin
#

compared to having enums which only contain a single variable / just an int and not int, float, etc

leaden ice
#

That would be less data

#

less data = faster

#

but if you need the data

#

you need the data

glossy basin
heady iris
#

i would store the ID (and only the ID) on the block, and then have a dictionary or something that holds the block data

glossy basin
heady iris
#

there's just no reason to have every single stone block say "I am a stone block and have a toughness of 10"

leaden ice
#

Oh wait I see what you mean

#

yeah you don't need durability for 99.9% of the blocks

heady iris
#

I'd store damaged blocks as a separate, sparse thing

glossy basin
heady iris
#

assuming you can slowly destroy a block, like in minecraft

leaden ice
#

in minecraft you can only partially destroy a single block at a time

latent latch
#

^

glossy basin
leaden ice
#

So it's not even a dictionary

heady iris
leaden ice
#

it's just a single coordinate

#

and a float

glossy basin
#

I see, this is very useful info

#

thanks!

latent latch
#

overall, you don't want one gigantic array of blocks loaded at all times

#

there's a lot of minecraft tutorials and how the chunks are stored

heady iris
#

i'd do it in a data-oriented-design style

glossy basin
heady iris
#

although I'm not sure how I'd actually render the blocks and give them collision

glossy basin
glossy basin
#

Just not quite sure wheter or not Compute Shaders can be any better compared to burst compiler

cosmic rain
#

They can. It depends on the job that needs to be done. But if it's a task that needs a lot of similar small parallel jobs(like a million), a compute shader would excell.

#

The more parallel jobs there are, the more CPU would lose to a GPU

glossy basin
#

Currently my mesh generation runs on a Ijob instead of an Ijob for, I tried to generate the mesh in parallel but for some reason my data was always wrong when using parallel jobs giving degenerated meshes ๐Ÿ˜…

#

I assume compute shaders wont have that issue right?

#

it seems like my job was losing data on the go when using IjobFor and native lists as parallel writer

cosmic rain
#

Yeah, parallel mesh generation would require some adjustments, since triangle order is important for meshes.

glossy basin
#

these were the results of our beloved artist IjobParallelFor

cosmic rain
glossy basin
cosmic rain
#

Probably.

glossy basin
#

I had 3 separated jobs, one for generating vertices, another for tris and another for UVS, I set the dependency of each to be the previous job handle

cosmic rain
#

Yeah, vertices generation would probably need to be done together with triangle generation, since they're interconnected.

glossy basin
cosmic rain
#

Look up race condition. That's basically the issue that you were experiencing.

#

Very common in parallel programming.

glossy basin
#

I guess I can pull info from gpu back to cpu right? I mean for retrieving vertex positions and generate colliders

glossy basin
glossy basin
#

@cosmic rain sorry for the ping, but just curious, is it okay to use for loops into a parallel for or it just misses the point of IparallelFor by itself? the reason I splited triangles from vertices job was because their resulting arrays have different lenghts

#

so using different jobs would make their index value depend of the lenght I specified rather than having an extra loop inside

cosmic rain
glossy basin
cosmic rain
glossy basin
glossy basin
cosmic rain
cosmic rain
glossy basin
glossy basin
#

1 sec pls

cosmic rain
#

Do note that the uv code might also need to be adjusted.

glossy basin
glossy basin
cosmic rain
# glossy basin https://hatebin.com/ilwiquylme

You could take your for loop iteration and run it in a parallel job.
The main issue is that you're adding the vertices.

vertices.Add(vert + blockPosition);

And relying on them being ordered when creating the triangles.

#

In parallel you don't know what vertex is gonna be added first. So you can't rely on the order there.

#

If you do want to rely on the correct ordering, you'll need to assign the vertices to the correct index in the collection manually.

glossy basin
#

Also makes sense why I was losing data over generating vertices in parallel, the array lenghts would always be lesser compared to the Ijob vertices lenght

cosmic rain
#

Or you could have a Triangle struct that contains the 3 vertices. You generate the 3 vertices, set them to the struct and append it to the Triangle collection. Then you could run a synchronous job that loops the Triangle collection, adds the vertices to vertices collection, while also constructing the triangles(indices) collection.

glossy basin
#

I will take that approach for sure

#

now, I have seem there is an extra API that lets you process mesh data into a job which is the MeshData API, but I guess in this case I should just add the vertices in the main thread in order to not lose data right?

#

or should I just stay with standard mesh system

#

I used it into a previous project, it is pretty hard to setup, and all the examples I could find of it rely on already generated meshes rather than procedural meshes

rugged storm
#

yo is there a way to make something run when a new class is made? like say checking if one of it's parameters are null and then setting it to something?

cosmic rain
cosmic rain
glossy basin
rugged storm
#

instance of a class! sorry I wasn't sure on the terminology

cosmic rain
rugged storm
#

like say I'm setting list "PartyMembers" via the unity inspector, but one of the things that make up each entry in party members is not serialized so i can only set 1 half of it, Id like to check if that other half is null and set it to a default

rugged storm
#

this should be better context, its saying OnValidate will be unused

latent latch
#

onvalidate is mono

leaden ice
rugged storm
#

AH okay, my point was is there a way i can do it for Non MonoBehaviour things?

leaden ice
#

Using a custom property drawer

cosmic rain
#

Or validate it from the MonoBehaviour that serializes it.

rugged storm
#

this is contained on a ScriptableObject

cosmic rain
#

Then from the ScriptableObject

latent latch
#

could just make the class a mono and implement your own initializer

cosmic rain
#

You could also probably add default initialization in the constructor

latent latch
#

or that haha

glossy basin
cosmic rain
#

There's no way to do that from the C# side. You'll need that handled in the shader, although, it's gonna be tricky either way.

rugged storm
old nymph
#

Hi, I'd like to ask if there's any way to improve model smoothness? I've tried increase anti aliasing and enabled auto smooth in import settings.

lean sail
#

Is there a way to see what force value is applied to a rigidbody (player) in the collision of another rigidbody (cannonball)? Or is there a better way to do what I am trying?

Im trying to limit my players move speed to a max which is easy, but this comes with the effect that the max gets applied even when the player gets hit with extreme force. I want them to ragdoll in such a case and still get tossed around fast.

Desired interaction: player walks around with max velocity=10, cannonball hits them and player max velocity=40 while they ragdoll

But i cant just check collision with cannonball and set speed = 40 or else the player can touch one on the ground and get a massive speed boost. So i was wondering if I could check what force the cannonball would apply to the player, and conditionally adjust the max speed based off of that.

(Or maybe theres a way to just have the input apply a max of 10 while not directly limiting rb.velocity which is what im doing rn)

idle coral
#

Can someone here help me?

#

I have no idea how to fix this and I don't see anything wrong with my code

quartz folio
tawny elkBOT
#
Visual Studio guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

โ€ข Visual Studio (Installed via Unity Hub)
โ€ข Visual Studio (Installed manually)

idle coral
#

Do I install the top one or the bottom one?

quartz folio
#

You don't install either. You click the one that relates to your situation and follow the instructions

idle coral
#

Oh, okay

#

Thanks

quartz folio
#

After it's configured then your problem is likely that you have accidentally duplicated your script

idle coral
#

THANK YOU!!! I just now looked for and found the duplicate!

#

You just saved me from a massive headache!

quartz folio
#

You still must configure your IDE. It's extremely painful to code without it, practically a waste of time

turbid surge
#

Im trying to get the edge of a sliders fill rect but no matter what the slider value is at the fills AnchorPosition stays at 0,0. I assume this has to do with my anchor/pivots but I cannot move those as the slider is dependent on them to keep the fill within bounds of the background. Can anyone advise on this?

soft shard
turbid surge
#

I mocked up what I am trying to do in code in below image. As the bar progresses, checkboxes appear. I wanted them to instantiate and set location to the rightmost edge of the fill rect as the slider val increases

rugged storm
#

hay is this a good way of doing specifically the updateParty and and ReplaceMember methods?

#

I'm fairly new to unity and just trying to learn if there are any ways I can optimize or write this sorta thing more efficiently

latent latch
#

if it's your first project I suggest you just continue on if it works without trying to optimize

latent latch
#

probably get an answer in the morning

turbid surge
#

alright ill copy paste it there

rugged storm
# latent latch if it's your first project I suggest you just continue on if it works without tr...

Fair but I've been told that before by a friend when I asked a similar question about taking inputs, but I would really like to learn better ways of doing things sooner than later so it's frustrating to hear.i just feels like this could be done better and faster tho I guess I'm falling into that "taste clashing with skill cuasing you to over perfect everything leading to you never finishing your art" thing so I'll accept your advice

latent latch
#

You can always refactor your code later. You're not likely to run into performance problems either until you much later (most of the time it's some unity feature and not your scripts), so I suggest keep going with whatcha got.

soft shard
glossy basin
#

hello there, I got this smooth mouse look effect, but whenever I walk and look around , the movement feels very glittery

https://hatebin.com/rjdfehtpvs

#

My movement script manipulates rigidbody velocity instead of adding force to it but I am not quite sure if this is the cause of the problem, the movement script runs on fixed update, I am almost certain the mouselook is the issue

shell scarab
glossy basin
shell scarab
# glossy basin Ohhh, let me try this

I also read online something about possibly using the screen refresh rate to smooth the camera rotation? I can't find it rn tho so I'm not sure, but maybe you can.

glossy basin
shell scarab
#

yea not sure, I never did it but maybe it could be helpful

sacred sleet
#

how would I randomly generate an Island ensuring there are a certain number of structures on it at all times

hard estuary
half dawn
#

So I have a basic project that was working fine but when I uploaded it to WebGL a few things broke, I've gotten the basic in editor version working again but now my instantiation for projectiles is no longer working. There's nothing wrong with this function from what anyone can see right?

#
        
    Rigidbody bulletClone = (Rigidbody) Instantiate(bullet, transform.position, transform.rotation);
    bulletClone.velocity = -transform.right * bulletSpeed;
    ammoCount(-1);
    string ammoValue=magSize.ToString()+"/15";
    magText.text=ammoValue;
 
 }```
#

Everything but the Instantiate is working as expected

vague slate
#

How to multiply quaternion by time delta?

#

basically I have some rotation

#

I want to apply to other rotation

#

but I also need to differentiate it by delta

soft shard
vague slate
#

this is rather expensive

#

first you gotta achieve total target rotation by quat mul

#

then slerp it

soft shard
#

Well if you know the rotation you want you can pass that, if you want it progressively some value ahead of what it is (a direction), you could add that, maybe with Quaternion.Euler

vague slate
#

nah, this is overkill. Hopefully there is a simpler alternative

topaz gate
#

Can someone please tell me why "Private" is underlined red?

#

private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.isWriting)
{
stream.SendNext(BubbleSpeechObject.active);
}else if(stream.isReading)
{
BubbleSpeechObject.SetActive((bool)stream.ReceiveNext());
}
}

vague slate
topaz gate
#

I am using a tutorial and it has private there but its not underlined red

soft shard
vague slate
soft shard
long ore
#

Has anyone used 2 Firebase apps in a singe Unity project? Is this even possible?

topaz gate
#

Guys i fixed one thing but now this isnt working here is my Update function

#

private void Update()
{
if (photonView.isMine)
{
if (!DisableSend && ChatInputField.isFocused)
{
if (ChatInputField.text != "" && ChatInputField.text.Length > 0 && Input.GetKeyDown(KeyCode.Slash))
{
photonView.RPC("SendMessage", PhotonTargets.AllBuffered, ChatInputField.text);
BubbleSpeechObject.SetActive(true);

                ChatInputField.text = "";
                DisableSend = true;
            }
        }
    }

}
#

And here is the error

#

NullReferenceException: Object reference not set to an instance of an object
ChatManeger.Update () (at Assets/ChatManeger.cs:27)

#

It brings me to if(!disablesend && ChatInputFeild.isFocused)

long ore
#

looks like something is null in your code, probably ChatInputFeild

topaz gate
#

Ill show you my Awake function

#

private void Awake()
{
ChatInputField = GameObject.Find("ChatInputField").GetComponent<InputField>();
}

long ore
#

to be 100% sure that you don't miss the reference, just set it from the editor

topaz gate
#

Ok

#

Its not letting me

knotty sun
topaz gate
#

Its was a TextMeshPro one

#

I am replaceing it with a legacy one

#

But i cant put it in the editor

#

It wont let me

knotty sun
#

you will need to change the type of ChatInputField to the correct one

topaz gate
#

Wait nvm i got it

orchid bane
#

Anyone here familiar with GameAnalytics SDK? Does it require only to create its premade GameObject or you have to write up some scripts in order for it to work?

tardy mortar
#

About UI management, do you think it's better to group all in one manager class or separate into different small classes?

heady iris
#

in my most recent game, I have a single InterfaceController, but its job is strictly to turn smaller classes on and off

#

one of those smaller classes is GameMenu, for example

#

roughly equivalent to this menu screen from Nioh

#

and then each sub-menu is its own class as well

#

e.g. Equipment

tardy mortar
#

that seems a good approach

heady iris
#

yeah, it means that each sub-menu can exist on its own if needed

keen solstice
#

NullReferenceException: Object reference not set to an instance of an object

drifting crest
flat heart
#

I've installed the LTS unity editor for 2021 [ver 2021.3.23f1] and i've created a blank 2d project and this error shows up, can someone help me?

heady iris
#

this is a bug with the Version Control package

#

if you aren't using it, then you can remove the package

flat heart
#

thank you

real pulsar
#

hi can someone please help me out with my project I'm really stuck at some things pleasee

heady iris
#

please go through that first

ember ore
#

Anyone here having experience with GLTF2?
If so... can i also e.g. export prefabs in unity to GLTF2 to load them at runtime (e.g. from web) later?
And what about components on such prefabs?

heady iris
real pulsar
#

I have a detection app that detects people moving in a certain area, it assigns person ids to the person and send to me in unity, I instantiate gameobjects that get the current positions from server and move them from left to right and right to left, basically trying to immmitate their movements in a 2d scene.
Right the gameobject leaves multiple clones behind it that stay on the screen without any purpose I want to destroy them.

cobalt wave
#

somnolent: hi I'm stuck
refuses to elaborate

cosmic rain
#

Congratulations

cobalt wave
#

that joke really blew just cuz of my wifi

cobalt wave
real pulsar
#

okay, so the problem is

#

my gameobjects starts flickering sometime

#

and whenever the id changes from the detection model it still sends it to my unity

#

and because of that clones are created but those clones stay on the screen

#

i want to destroy them

#

and make the whole thing be smooth

#

like if a person comes the gameobject should move according to that and then be destryoed when it is outside of the screen

#

the only thing is I dont have much time

#

so stressed about it since last few days

#

and have to make it work

heady iris
#

so every time the detection model loses track of a person, the game object gets left behind

#

and then when it notices them again, a new object is created

real pulsar
#

yes

#

exactly

heady iris
#

perhaps you should have the object keep moving with whatever velocity it had when you lost track

real pulsar
#

can I show you through video

heady iris
#

and then, when detecting a new person, it should see if there are any "lost" objects near their position

real pulsar
#

yes

heady iris
#

what kind of data are you getting from the detection model?

#

does it just send you a list of IDs and positions on a regular basis?

real pulsar
#

id, positions

#

other things im not really using anymore

deep fable
#

Is there a way to revert all changes made since I opened the Rider IDE today? (I did not git commit)

heady iris
#

oh wait

#

sorry, I misunderstood: you are using Git

deep fable
#

I mean I am using Git but I didn't commit today and yesterday, but I want to revert back to when I started today

heady iris
#

Rider might have some kind of file history you can use. I know VSCode does.

#

I can click on one of those to go back to an older version of the file

deep fable
deep fable
glossy basin
#

Hello there, does anybody have the definitive rigidbody character movement and a smooth mouse look? My scripts seem to have conflict with each other resulting in glitter movement

cosmic rain
#

glitter?

glossy basin
#

from what I can see, the mouse look is the issue here

cosmic rain
#

jittery you mean. Glitter means something else entirely ๐Ÿ˜„

glossy basin
#

So yeah, my mouse code seems to cause this issue, when I disable it and move around, everything looks as expected

cosmic rain
#

Jitter happens when the movement is not updated at the same rate as the rendering.

#

*movement or rotation

glossy basin
cosmic rain
#

One common cause is if your movement is physics based(updated in fixed update) and the interpolation is not enabled/working.

cosmic rain
glossy basin
#

I modify velocity instead of adding force

cosmic rain
#

Even if interpolation is enabled, it doesn't mean that it's working.

#

If you're moving or rotating it via the transform, for example, that would break the interpolation.

#

First determine what conditions cause the jitter

glossy basin
lean sail
cosmic rain
#

Well, that's gonna break interpolation for sure

glossy basin
#

Ah maybe it was because my character would just slide when using add force

lean sail
#

changing velocity directly might run into issues where u cancel out other movement like if u get tossed really fast

#

then u gotta set a max speed, but im actually having issues with max speed taking not letting me get tossed fast either so idk what to suggest there

glossy basin
#

Im gonna try that out

cosmic rain
glossy basin
#

so I dont face that problem

rain minnow
lean sail
#

How does addForce work anyways?
If i add force inside fixedUpdate, the velocity doesnt change until Update from what i tested. So idk how to set a max speed inside fixedUpdate as well, i run into issues where the max speed gets set to 8 but since the force seemingly gets applied in update, it becomes 8.16. The 0.16 is because thats 8 * fixedDeltaTime

tropic quartz
#

Yeah well made kinematic controllers can be amazing, but as your everyday Unity fiddler I can tell you that mine tend to be horrid. lol
If you wanna make your own controller it's usually easier to just use forces.

There's a pretty popular free kinematic controller in Unity Asset store, though. iirc.

leaden ice
#

which happens right after FixedUpdate

#

it does not happen in Update

glossy basin
lean sail
rain minnow
#

Yep, regardless of where you set/ assign the velocity, in Update or FixedUpdate, it won't take effect until the physics step . . .

leaden ice
cosmic rain
#

Yeah, you can also calculate how much force needs to be applied to reach certain velocity.

lean sail
#

I was thinking of decreasing the force as i got near the max speed, but then turning around would also be really slow. I might just try changing velocity then in my move function and only limiting it there. That should allow my character to hopefully get ragdolled at high speeds

#

thanks still, i actually did look at that execution order but i didnt really understand where the addforce step was done. I thought it was done at the same time as fixedupdate

heady iris
#

in practice, you reach a 'max speed' because air drag + ground friction = forward force

#

(or just air drag, if you're airborne)

cosmic rain
#

I mean, adding force is almost the same as setting velocity.
Ignoring the mass of the object, if, let's say you want to set Velocity of 2,0,0 when the current velocity us -1,0,0, you just add impulse/velocityChange force equal to (3, 0, 0)

#

or you can do that with Force(default)/Acceleration mode by also dividing(I think) that vector by fixed delta time.

heady iris
#

right, since applying 50 newtons of force for 0.02 seconds will get 1 kg object moving at 1 m/s

#

of course, you might as well just use the appropriate force mode and not deal with the extra step

rain minnow
#

both of these have the same effect:

rigidbody.AddForce(Vector3.forward * 1f, ForceMode.Force);
rigidbody.velocity += Vector3.forward * (1f * Time.fixedDeltaTime) / rigidbody.mass;
```so you can use velocity if you know how to apply the force (dependent on force mode) . . .
lean sail
#

i guess then my whole error came from the fact that the velocity was changed later than i thought

#

ive been fine tuning this rigidbody movement for too long at this point

#

thanks everyone for the advice and specifics, it was really helpful ill try to get it working from here

rain minnow
#

the thing is, whichever method of physics movement you choose, you must use it for everything, don't intermix . . .

viscid kite
#

For coroutines, is it possible for a coroutine function to have a waitforseconds and waituntil albeit separated by say an if/else block?

wide terrace
#

sure

leaden ice
hushed needle
#

i have a 2d project and i want my player animation to change depending on the cursor position(red circle = normalized vector). like this:

#

the problem is i don't know how can i write this with code. i wrote some code but that doesn't work. there is any better way or my coding skills are not enough?

leaden ice
#

(and FloorToInt)

swift falcon
#

Hello there, can anyone help me with this warning message "Unable to find player assembly: C:\Users\JURAJ\Unlock And Explore the underground\Temp\StagingArea\Data\Managed\UnityEngine.TestRunner.dll"

#

warning is annoying, it seems to not affect game after building it, but still I want to fix it.

swift falcon
leaden ice
#

Nope

#

Pretty sure that's where Unity puts ome temporary build artifacts

swift falcon
#

oh

#

alr

#

thanks

austere lodge
#

Would this work?

stone leaf
#

Gathering opinions. Has anyone found a newer or better endless procedural terrain tutorial to follow than the Sebastian Lague ones that are about 7 years old?

Link: https://www.youtube.com/watch?v=wbpMiKiSKm8

Welcome to this series on procedural landmass generation. In this introduction we talk a bit about noise, and how we can layer it to achieve more natural looking terrain.

A quick summary:
'Octaves' refer to the individual layers of noise.
'Lacunarity' controls the increase in frequency of each octave.
'Persistence' controls the decrease in ampl...

โ–ถ Play video
hushed needle
glossy basin
swift falcon
#

do you know what could be causing this warning since I see a lot of people had this same warning here

glossy basin
#

keep in mind that there are a lot of noise functions to mess with so you can get some different results depending of what you are looking for

stone leaf
leaden ice
#

that's for 3D

#

you might have to adjust some of those direction vectors if you're in 2D or whatever

#

but that's the gist of it

stone leaf
glossy basin
#

Not sure about LOD (I did not watch the full series) but I dont think unity does LOD for procedural terrains

cinder falcon
#

does anyone know of any resources where I can find specifics about how to make grapple points?

#

for 2d specifically but idk if it matters

glossy basin
#

also, If you are curious about some noise patterns for procedural terrain, you can watch the GDC talk of no mans sky where they explained what kind of noises they use and their effects on terrain

swift falcon
glossy basin
swift falcon
#

I will now both

glossy basin
#

if you have a temp folder delete it too

#

temp is where the problem comes from

swift falcon
#

it's in library I think

glossy basin
swift falcon
#

yes ofcourse

ocean river
#

i have a gameobject, and a child gameobject. when i rotate the parent childobject, i want the childs rotation not to change with the parent ones
is that possible?

potent sleet
#

that's whole point of parenting

ocean river
#

but i need it to move with the object...

#

not the rotation tho

wide terrace
#

You could apply an equal and opposite rotation to the child... or a Rotation Constraint component... but it would be better to not have it as a child

potent sleet
ocean river
#

so theres no build in way to lock it
alright...

glossy basin
wide terrace
#

Or consider using a common empty game object as the parent of both. Translate the common parent to move them both, rotate the child for independent rotation.

swift falcon
glossy basin
#

not a real question but just asking for feedback, is it me or unity default gravity feels like moon gravity by default? It may only be my perspective but I feel like the actual gravity does not feel as accurate as it is supposed to be

glossy basin
leaden ice
#

how big is "small"

#

looking for concrete numbers

glossy basin
#

scale of 1, 1.5, 1

leaden ice
#

a human is about 1.75 meters tall

swift falcon
glossy basin
leaden ice
heady iris
#

try jumping irl

leaden ice
#

The large size contributes due to the "godzilla effect". Large objects tend to seem to be moving very slowly but it's a trick of perspective and distance and how your brain interprets things.

heady iris
#

indeed

glossy basin
#

Ohhh, interesting concept, didn't know it had that name

leaden ice
#

idk if that's a real name or something I made up lol

#

also I just googled it and - don't google it ๐Ÿ˜†

glossy basin
glossy basin
buoyant crane
glossy basin
languid pilot
#

I've imported com.google.play.appupdate package and I've start getting this error in console. I find out that if i enable all conection over HTTP, then there is no problem. Is there a way to only enable google one?

glossy basin
#

did somebody mention me? lol just saw a ping

wheat spade
#

I have found a really weird bug. My variables in the GameManager script start out with assigned values. E.I. private static bool example = false, when output with the debug console at the start of the awake function, is true. This problem persists even if the GameManager is the first in script execution order. The weird part is it only happens in builds of my game. The editor works fine. The problem variables are also static, if that matters. Does anyone know if Unity does something special with the GameManager script that is causing this, or something else?

shell scarab
#

So if you play two separate scenes in the editor, itโ€™ll work fine, but if you transition scenes itโ€™ll be the last value it was set to when it calls the Awake function

#

Perhaps thats the problem?

wheat spade
#

It is the first thing that happens in the game. The Debug.Log reveals the awake function is only ran once. No scene changes occur.

shell scarab
#

Well somethings changing it bc itโ€™ll compile as false so it wouldnt ever be true unless something changes it, and it cant be serialized since its static so itโ€™s not unity doing it.

#

Without any code to look at its kinda hard to do any debugging

wheat spade
#

It isn't my code. I added it as a testing variable after my static singleton was doing the same thing. It is only referenced in it's initialization (what I posted before) and it's Debug.Log.

#
private static bool isGameManagerAssigned = false;

private void Awake()
    {
        Debug.Log(isGameManagerAssigned);
    }
``` Outputs true in build, false in editor.
shell scarab
#

So its not that itโ€™s changing by itself, itโ€™s that itโ€™s not getting changed? Your original question was a bit confusing in that regard.

#

If this is the only place its references how would it ever be set to true?

wheat spade
#

That's what I'm wondering.

zealous tundra
#

Hey guys, I'm trying to retrieve the number of ContactPoints2D of a BoxCollider2D with the GetContacts() method, but I don't see any way of accessing the boxcollider's contacts array, could anyone help me with that?

shell scarab
#

That method literally returns an array of contacts wym?

gray mural
#

Hey, does somebody know to do to such a hower effect in c# script?

zealous tundra
shell scarab
zealous tundra
#

it returns an integer

shell scarab
#

Youโ€™re totally right, I was misremembering.

#

Itโ€™s collision.contacts

zealous tundra
#

huh

glossy basin
gray mural
shell scarab
# zealous tundra huh

If thereโ€™s contact points thereโ€™s a collision. If thereโ€™s a collision it calls the collision methods such as OnCollisionEnter2D, which takes a collision2D parameter (or something similar), which you could then do collision.contacts to get an array of contact points.

zealous tundra
#

But it's just gonna be the amount of contact points for that single collision, I'm trying to get the number of all collisions

#

If I'm understanding correctly

shell scarab
#

Why not just process them as they occur? If youโ€™re just getting the number count it yourself, + on enter - on exit

#

@zealous tundra thereโ€™s also Collider2D.GetContacts()

zealous tundra
#

I tried doing that but it doesn't work in my case

#

let me explain

shell scarab
#

ok

zealous tundra
#

damn i spilled my water ๐Ÿ˜ญ

#

brb

shell scarab
#

๐Ÿ˜ญ

inner escarp
#

Does anyone have any experience with setting up skills for RPGs?
In my game, players are able to choose which skill goes on what slot, so I can't just hard-code it into a button.

I'm having a hard time wrapping my head around the idea when it comes to custom effects. Like, one skill could be an attack, buff, debuff or passive. Or it could be something like a Movement speed buff / teleport

Any ideas or input would be appreciated because I'm genuinely just stumped atm

shell scarab
#

Are you asking what skills you should make?

inner escarp
#

No. Moreso how to handle them. I already have a list of skills that the player can have

shell scarab
#

What do you mean handle them?

inner escarp
#

At first, I was going to go with ScriptableObjects but they don't have access to Couroutines, which I was going to use to handle cooldown / duration

shell scarab
#

I still dont know what you mean to โ€œhandle themโ€.

zealous tundra
# zealous tundra let me explain

I have a single player collider that I want to keep track of its current colliding sides, like up, down, left and right. I want to know when exactly the collider's side starts and stops colliding, to for example know when the player can wall jump. So it's not only about the number, it's about which side does the collision come from. I already have a method that does the second part, but I want to have a method that updates bools of which sides of the player are colliding with stuff whenever the player enters or exits the collision.

rugged storm
#

hay how do i accept a prefab in a script?

buoyant crane
shell scarab
rugged storm
#

Ah as a GameObject, thanks

shell scarab
zealous tundra
#

i think

#

lol

shell scarab
#

Just have 4 sub-objects with edge colliders as arrange them into a square, then you can do the contacts method to count the contacts for each side

zealous tundra
#

even with continuous collision detection

shell scarab
zealous tundra
#

That's what I currently have

#

But the thing is

#

When that collider exits a certain collision I don't have access to the collision points of it

#

so I can't determine what from what side is it exiting a collision

shell scarab
#

OnCollisionExit2D doesnโ€™t work?

zealous tundra
#

nope

inner escarp
# shell scarab I still dont know what you mean to โ€œhandle themโ€.

Like... how would I be able to keep skills unique but also have them accessible for a slot system?

Let's say I have the following skills:
โ€ข A dash skill
โ€ข An attack skill
โ€ข A Debuff skill

I'm looking for a way to add each skill into any slot that the player chooses (which they can change), and have it function properly.

For example, if I pressed the Dash skill, it would make the player dash forward etc. It would be easy to handle this if I hard coded the logic and stuff into a slot itself, but since I'm making the positions of the skills in the slot customizable, I need to go with a different approach

Probably a shit way of explaining it, so sorry in advance lol

shell scarab
zealous tundra
#

I mean, the method does work but I can't access the contactpoints of an already exited collision

#

I'm preety sure I tried that

heady iris
#

the slots should barely matter, really

#

you just have a list of equipped skills (and maybe corresponding keybinds)

shell scarab
buoyant crane
shell scarab
buoyant crane
#

General idea is that your player doesnโ€™t know how to perform the ability, your skill should handle that

zealous tundra
heady iris
#

I wrote a system up for an RTS game (well, more of a moba, I guess: lots of active skills)

#

the abstract skill class tells you things like "this is a unit-targeted ability" and "this ability needs to channel"

#

but all of the actual behavior is contained in the specific implementations

buoyant crane
#

ah true

latent latch
#

The only thing my abilities have is usually a reference to the source player for some calculations such as killing blow ect

zealous tundra
shell scarab
inner escarp
shell scarab
#

Unit-target and channeling are skill-specific, or at least make another abstract class that extends skill

inner escarp
buoyant crane
heady iris
#

consider: an ability that can ground-targeted OR unit-targeted

#

or even self-targeted, by double-tapping it

latent latch
#

I fixed that problem by making everything I do AOE

shell scarab
heady iris
#

...if you wanted to inherit from two things?

shell scarab
#

You canโ€™t inherit from 2 classes

heady iris
#

it's a problem in any inheritance-based system

#

i guess it's not the diamond inheritance problem if it's impossible from the start

latent latch
#

Yeah, there's a lot of cases where you have to throw on some interfaces to untangle some of the logic

shell scarab
#

Even then not really in this pretty basic implementation of inheritance

heady iris
#

i made ability targeting happen outside of the ability itself

#

the targeting system asks the ability if what i'm pointing at is a valid target

shell scarab
heady iris
#

(and ask about both the ground and the unit i might be hovering on)

#

if nothing is valid, you get a big angry red cursor

zealous tundra
#

lol

latent latch
#

I got rid of direct targeting since it started to create more complexity on a dynamic spell system I wanted to make

shell scarab
zealous tundra
#

to uh

latent latch
#

I found that targeting an area or point direction is the idea way to really meld stuff together

shell scarab
#

Just do other.contacts from the start??

zealous tundra
#

get the first contact points of the array lol

heady iris
#

wait, is that valid C#

#

GetContacts returns an array

shell scarab
#

contacts[1]

zealous tundra
#

I think

zealous tundra
heady iris
#

you're subtracting an integer from an array...

simple egret
#

(you should set up your code editor so it highlights errors, your syntax was invalid)

shell scarab
#

no, access an index of it. Contact[0] would be the first item in that array

shell scarab
heady iris
#

oh!

#

right

#

you give it an array, and it returns the number of contacts stored in the array

zealous tundra
#

there is no error

shell scarab
simple egret
#

Yeah it works, I saw GetContact() (singular)

heady iris
#

anyway, it sounds like there are just zero contacts here

shell scarab
heady iris
zealous tundra
heady iris
#

it's a non-allocating way to get a variable number of results

zealous tundra
#

it works the same way ๐Ÿ˜ญ

heady iris
#

the int that gets returned lets you know how many slots in your array were actually used

shell scarab
heady iris
#

oh, I think I see what was going on here

#

you passed other.contacts to other.GetContacts

shell scarab
#

Thats not whats happening man

heady iris
#

if that array was empty (it probably gets lazily initialized to avoid allocating memory when not needed), then it would see that you gave it an array with zero elements in it

#

and thus put zero elements in the array

#

and return zero

#

you're supposed to pass your own pre-allocated array to GetContacts

zealous tundra
shell scarab
#

Wtf are you even talking about!?

simple egret
#

Wait is this to get the contact count? Collision2D has a contactCount property

shell scarab
#

You need to specify youโ€™re talking about Collision2D.GetContacts!

heady iris
worthy perch
#

Hello, I have this code to click on a specific GameObject collider and show its UI to upgrade it, but when an enemy approaches its colliders this code stops working, there is some order of priority that is preventing the raycast from reaching to the collider that I want

shell scarab
zealous tundra
#

true

heady iris
zealous tundra
#

I still don't know how to get the number of collisions of that collider

heady iris
glossy basin
#

Ahhh so its contact points, that is different

shell scarab
#

that wont work if yaโ€™ll would read what theyโ€™re trying to do lol

zealous tundra
heady iris
glossy basin
austere lodge
#

Yo why does my console warn me that says "Failed to fetch saved variables from player prefs:" and I can't see how to fix it

shell scarab
#

So the collision exitโ€™s contact points array is 0 width?

simple egret
#

Get the direction between the collider center and the first contact point, then dot products or angle to find the side?

simple egret
#

Or, just use 4 colliders

#

One per side

zealous tundra
#

Already tried that

heady iris
shell scarab
lament mural
#

So I have the following problem: I'm using a rigidbody for my character. It has a physics material of friction 0 and bounce 0 (uses min value for both). Friction is 0 because I'm calculating and applying friction manually when the character is grounded.
When my character lands on a slope from a long fall, it slides a little before it stops.
Any ideas on how to prevent it from sliding on landing? I tried canceling velocity on OnCollisionEnter and also on FixedUpdate but nothing seems to work. I'd rather avoid Update because I want to keep the movement as frame-independent as possible.

zealous tundra
shell scarab
simple egret
#

I wasn't there at that time, lol

heady iris
#

you'll still want to hear about both collision events

simple egret
#

And don't make them overlap

heady iris
#

overlapping shouldn't really matter here

#

you can still have a big collider come flying in and hit two of them at once

zealous tundra
shell scarab
#

Iโ€™ll let you guys go through it then. I tried everything i could think of without saying to do it a different way.

heady iris
zealous tundra
heady iris
#

well, then don't make the head hitbox gigantic

zealous tundra
#

it's a 2d game btw

heady iris
#

i'm just saying that it's reasoanble for the "left" and "top" colliders to have some kind of overlap

#

you can, of course, design them however you'd like

zealous tundra
#

how is that reasonable?

heady iris
#

it depends on your game

zealous tundra
#

I don't really get it

heady iris
#

i'm not sure why there's a huge hangup about it, though

lament mural
zealous tundra
#

I don't want a single bullet to deal damage to two parts of the body

heady iris
#

just make the colliders nice and distinct if that's an issue

zealous tundra
heady iris
#

you can also do some logic to avoid duplicate collisions

zealous tundra
#

let me explain

heady iris
#

if the same collider hits twice, ignore the second hit

rain minnow
# zealous tundra .

wait, you just want to know or add to a counter when collision from a side occurs and remove it when the (collided) object exits? how are you checking for the collision from each side? individual GameObjects with a Spherecast/XXXCast, or a single collider by checking the direction of the collided object to the main object?

heady iris
#

again, this is a question of game logic

rain minnow
#

cool, using gameObject here is unnecessary though . . .

zealous tundra
#

oh right

heady iris
#

comparing the contact points seems kind of weird

#

i guess it works if everything's an unrotated rect collider

zealous tundra
#

I'm checking how are those aligned this way

heady iris
#

can you describe the higher-level gameplay logic you want here?

#

not the specific implementation

#

that will help me understand what the best option is

heady iris
#

that is the implementation. I'm asking about the gameplay.

zealous tundra
#

Do you mean how do I want to use those collision bools?

heady iris
#

Right.

#

You may be experiencing the XY Problem -- getting stuck on one specific solution when the original problem has a better way of being solved

zealous tundra
#

To check whether the player is colliding ONLY with a wall (collision only from left ot right side), to check whether a player is still in collision with a laser (that's taking hp constantly when collided with)

#

and it might be very useful later on

heady iris
#

So if you're getting lasered, then you shouldn't be allowed to do a walljump, or whatever

zealous tundra
#

those are two different examples I gave you

solemn raven
#

hi , im looking for a way to draw a circle in a shader and I came across this function yesterday
does this line of code really draws a circle ? , how / or how to even test it ?
i copied it in my (to do list) but i forgot to keep the reference link so i dont know how it works really , but it's just 1 line of code.

float DrawCircle(float2 pos, float radius){return length(pos) - radius;}
heady iris
#

so, for the laser thing, you don't care about direction at all

#

actually, let's make a thread for this

#

collision

zealous tundra
#

one is checking whether in a single moment the player is colliding with only with a wall

leaden ice
rain minnow
# zealous tundra

this would be much easier if you used separate colliders to detect a collision from each side. then you can tell which side has a collision . . .

neon plank
#

Question:
How this code can produce the following exception?

MissingReferenceException: The variable renderers of TimeRoot doesn't exist anymore.
You probably need to reassign the renderers variable of the 'TimeRoot' script in the inspector.

It doesn't make sense, I'm already checking for null in the line above.

leaden ice
# solemn raven hi , im looking for a way to draw a circle in a shader and I came across this f...

drawing things in shaders doesn't really work like the way you're thinking. There wouldn't be a function like "DrawACircle()" that imperatively draws a circle.

Shaders are programs that run on a per-pixel or per-vertex basis. So for example a fragment shader is a program that runs on a single pixel and determines what color that pixel is. So I would expect a fragment shader that draws a circle to do something like, conceptually:
"Is this pixel within the circle? If so, make this pixel red. If not, make this pixel transparent".

#

the end result when that is run on every pixel in an area is you get a circle drawn on screen.

rain minnow
heady iris
#

although, I do not see a variable named "renderers" in this screenshot, indeed

neon plank
#

Then the exception it's giving me the wrong line

solemn raven
neon plank
#

And yet, renderers is an array, arrays can't be "Missing", it is null or not, and didn't get a NullReferenceException when I created the span

heady iris
#

well, the compiler doesn't lie

#

make sure your code saved, make sure it compiled in unity, and give it another go

leaden ice
#

it's just like Vector2.magnitude in C#
note that pos is a float2, not a float which is the same as Vector2

neon plank
#

So I'm not understanding what is going on then

heady iris
solemn raven
languid pilot
#

Anyone knows what's can be wrong?

floral kiln
#

Hey guys, I need to apply a fix to this, it was my bad that I wrote it poorly, but have to deploy a fix fast:

long lastDateLong;
DateTime lastDate = DateTimeOffset.FromUnixTimeSeconds(thisDateLong).DateTime;

bool within24hours = (DateTime.Now - lastDate) <= TimeSpan.FromHours(24);
            
if (within24hours) {
                // do something
}

This code checks if lastDate was 24 hours ago from right now, but what if it needs to check is if lastDate was yesterday vs today

#

So like if it's past 12am from the lastDate's day

#

Anyone know how to do that?

languid pilot
# floral kiln Anyone know how to do that?

๐Ÿ‘ How to work with date and time. In this tutorial we'll focus on the system date. How to get it, and how to format it.

๐Ÿ‘ Extra tip: You can get the NAME of the day by typing "ddd" or "dddd". Try this:
print("Today is " + System.DateTime.UtcNow.ToLocalTime().ToString("dddd"));

ยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยทยท...

โ–ถ Play video
silk tinsel
#

Does anyone know how the coordinates are set up for Texture2D.GetPixels()? If I wanted to start at the top left pixel is that (0, 0) or (0, texture height)?

floral kiln
#

Ah I see, so you can even do DateTime.AddDays(-1) and check that way

#

testing to see if it works with 24 hours versus a local timezone's actual day

simple egret
floral kiln
#

Wow

heady iris
#

DateTime.WhenIWillDoTheThing -> always returns tomorrow

simple egret
#

Watch out, only if DateTime.Procrastinate is true. Fortunately, that's a const bool and is always true

floral kiln
#

DateTime.WhenWillIDoTheThing = DateTime.WhenItsDue.AddDays(-1);

heady iris
#

are you sure you're looking at the right instance of this component?

#

there could be another object in the scene with it attached

rain minnow
#

which object highlighted when you clicked on the log from the console?

neon plank
simple egret
#

Can you post the full error message? It usually comes with a stack trace that points to the exact line that threw the exception

hexed pecan
#

So the latter (0, height) would be top left

#

To convert XY coordinates into an index in the color array, you can use y * width + x

neon plank
# simple egret Can you post the full error message? It usually comes with a stack trace that po...
MissingReferenceException: The variable renderers of TimeRoot doesn't exist anymore.
You probably need to reassign the renderers variable of the 'TimeRoot' script in the inspector.
WhiteboardGames.TempusVitae.TimeSystems.TimeRoot.ChangeElements (System.Boolean enable) (at Assets/Scripts/Time/TimeRoot.cs:192)
WhiteboardGames.TempusVitae.TimeSystems.TimeRootManager.InitializeRoots () (at Assets/Scripts/Time/TimeRootManager.cs:51)
WhiteboardGames.TempusVitae.TimeSystems.TimeRootManager.Start () (at Assets/Scripts/Time/TimeRootManager.cs:38)
silk tinsel
silk tinsel
simple egret
neon plank
hexed pecan
neon plank
silk tinsel
#

ok cool

simple egret
neon plank
#

Span<Renderer> renderersSpan = renderers.AsSpan(0, renderersCount);
And renderers is: [SerializeField, HideInInspector] private Renderer[] renderers;

simple egret
#

Okay so you serialize it, but hide it in the Inspector

#

Something isn't adding up here

neon plank
simple egret
#

It's complaining about your array yes

neon plank
#

The line is renderer, but the error is renderers

simple egret
#

Can you change the name of the array to something else?

leaden ice
#

Any chance you haven't saved your code recently or there are compile errors?

rain minnow
neon plank
neon plank
hexed pecan
#

So is there a variable called renderers at all?

neon plank
tardy mortar
#

is it possible to listen to a event without the class being instantiated?

leaden ice
hexed pecan
neon plank
#

Async loading an scene, the error happens when I change from one scene to another... but only 15% of times

hexed pecan
#

Hmm... That might be a clue

simple egret
#

Once you changed the array's name, try to get the exception and see if it's complaining about the array

leaden ice
#

you might just have a reference to a destroyed object in there

neon plank
leaden ice
#

and you can't see it because it's hidden

simple egret
#

So yeah it's definitely complaining about your array

#

Even if you access it "though" the span

leaden ice
#

Actually it's even weirder since it's an array

#

you'd expect the array itself to be fine - at worst only containing references to missing objects

simple egret
#

I'm pretty sure it's the mix of the two attributes here that makes the weirdness happen

tardy mortar
rain minnow
#

the attributes say, "i want to see you, but i don't want to look at you," lol . . .

neon plank
leaden ice
tardy mortar
leaden ice
#

and what code do you want it to run?

#

the event itself need not be static in that case but you'd need to get a reference to the particular instance on which you'd like to liseten for an event to if it's not static

#

basically - can you back up and explain what you're trying to do?

neon plank
#

Clicking the first message doesn't highlight anything. But the second one doesn't have the same element at the specified location, this obviously happens because I'm compacting the array during the iteration by filtering out nulls.
The weird thing, is that if I remove that cleaning, the error is not happening... or at least not in my current tests, it's difficult to know if it actually got fixed since it only happens 15% of times.

rain minnow
neon plank
#

Oh, just happened again...

neon plank
tardy mortar
# leaden ice basically - can you back up and explain what you're trying to do?

i'm using a singleton pattern that instantiates itself when it's called in the scene for the first time

so if I for example call UIManager.Instance.OpenDeathUI() when the player dies it works fine

tho I wanted to subscribe to the OpenDeathUI to the "onPlayerDeath" event and triggered it when the player dies instead of calling the UIManager on the player.

just wondering if that's possible

leaden ice
rain minnow
neon plank
#

Still different values

rain minnow
#

that causes all kinds of issues . . .

neon plank
tardy mortar
leaden ice
# tardy mortar i'm using a singleton pattern that instantiates itself when it's called in the s...

You'd basically have to have either:

  • The player call a function on UIManager to register itself with the ui manager where you can then subscribe to the event ont he player
  • Have whichever script that spawns the player pass a reference to the player to the UI manager
  • Make onPlayerDeath a static event and then you can just directly listen to the event from UI Manager in Awake or OnEnable for example
leaden ice
neon plank
rain minnow
neon plank
#

Ok

fast belfry
#

Not sure if this is the right place to ask, but has anybody tried setting up git with fmod plugin?
Should you gitignore plugin folder? Or will it break the integration and it's ok to store the plugin in the repo?

heady iris
warm shadow
#

So this function is suppose to focus the camera on an object, and it works great but only with Pitch above 0, as soon as it gets below that it snaps back to the top, and it repeats. The normal look around works without any issue, and can go below 0, Please help

public void FocusOnObject()
        {
            LockCameraPosition = true;
            if (focusObject != null)
            {
                CinemachineCameraTarget.transform.position = transform.position + camFocusPrePos;

                Vector3 targetDirection = (focusObject.position - CinemachineCameraTarget.transform.position).normalized;

                float singleStep = 5 * Time.deltaTime;

                Vector3 newDirection = Vector3.Slerp(CinemachineCameraTarget.transform.forward, targetDirection, singleStep);

                cinemachineTargetPitch = Quaternion.LookRotation(newDirection).eulerAngles.x;
                cinemachineTargetYaw = Quaternion.LookRotation(newDirection).eulerAngles.y;
            }
        }
leaden ice
#

for exactly the erason you're saying

warm shadow
#

okay

leaden ice
#

Or you can use Vector3.SignedAngle

warm shadow
#

How would you hack them together?

neon plank
warm shadow
# leaden ice Or you can use Vector3.SignedAngle

so replace the cinemachineTargetPitch = Quaternion.LookRotation(newDirection).eulerAngles.x; with Mathf.DeltaAngle(CinemachineCameraTarget.transform.rotation.eulerAngles.x, newDirection.x);?

heady iris
neon plank
heady iris
#

and what's the stack trace for this current script?

neon plank
#

For that I would need a moment to reproduce the bug with this script, but I would say it's the line enabledRenderersSpan[j] = renderer.enabled; (170).

sacred sleet
#

so I have this script that generates an island and places villages, caves and fountains on them, how would I get rivers set up?
code: https://hastebin.com/share/uxixoceneq.csharp

tardy mortar
deep fable
#

I don't know where to ask this question.. How would you go about rendering a crowd made of thousands of 3d people? (like in FIFA games) They should also be animated

leaden ice
deep fable
leaden ice
#

also a full stickman object is probably overkill

leaden ice
#

!collab

tawny elkBOT
rain minnow
#

!collab

tawny elkBOT
leaden ice
#

way too much memory usage

deep fable
lime widget
#

I have 2 colliders on my object. One circle2d and one box2d. I want to check if a box2d collider hit another box2d collider. How can I do that?

rain minnow
#

check the collider type of the collided object . . .

lime widget
#

Forgot to mention, the circle one is bigger than the box one and if i use OnCollisionEnter it will register the circle one

leaden ice
rain minnow
leaden ice