#archived-code-general

1 messages · Page 99 of 1

swift falcon
#

ngl did not know u could do ithis

#

in c#

#

knew you could do it in golang just not c# haha

ashen yoke
#

tuples?

swift falcon
#

return multiple values

ashen yoke
#

youre returning one

#

its a Tuple struct

#

syntax sugar

swift falcon
#

in go its like

func test() (bool, string) {
        return false, ""
}
twin hull
#

ok, that one would need SO but i can almost guarantee you're thinking about it wrong

fervent furnace
#

object/struct/ref/out, many way to return multi values

swift falcon
#

forgot about ref tbf

ashen yoke
#

they have different semantics so its not strictly return

languid hound
#

Just math related more or less: How would I calculate what torque is needed for something to reach a position?

ashen yoke
#

something about differential equations

potent sleet
#

Newton's second law of motion or sumthin

languid hound
#

Why can it not just be similar to desiredPosition - currentPosition man

#

So stinky

unreal valley
#

Here's my paint perfection of what I was trying to do @twin hull

#

Main Job System holds a list of the JobBase, So any job can be in there.

#

Then those Jobs have a leveling system attached to them to track exp etc etc etc

#

Think FF14/11

swift falcon
#

instead of jobs why not make trainable skills? so they can use all kinds of equipment

unreal valley
#

This wasn't really going to get implemented into anything, yet. It really was a learning experiment for myself.

swift falcon
#

ah i see, only reason i say this because old school runescapes combat system is very nice

#

simple but complex which is what im basing mine off

unreal valley
#

I was trying to make it so if i ever created another Job it would easily be able to be added to the list. But i guess im going about it wrong code wise

#

I understand what I want, just dont know how to do it fully.

#

Other than SO's

twin hull
#

It's mostly an inspector problem

#

Oop itself is fine

unreal valley
#

I suppose im relying to much on the inspector to fill in data rather than just doing it in code.

twin hull
#

SOs are a bit of a nightmare to work with, but for a learning project it might be fine

ashen yoke
#

why are they a nightmare?

#

in your case

heady iris
#

i had a bad start with them

#

i tried to do Bad Stuff

swift falcon
heady iris
#

like mutating assets

unreal valley
ashen yoke
heady iris
#

i probably misunderstood several parts of it

unreal valley
heady iris
heady iris
#

i was getting inconsistent behavior between the editor and the build

ashen yoke
#

yes its a fundamentally bad gimmick

swift falcon
#

for instance dont just do straight if/else comparisons

#

i kinda see what you mean like with items and stuff

#

but if your items derive from 1 base so that has the data just make sure that the enums sync up

heady iris
#

then it continued to feel clever (derogatory)

#

i'm now happily using SOs for tons of immutable data

#

weapon definitions, save points, currencies...

ashen yoke
#

when i first saw that talk few years ago that popularized it, i kinda ran the simulation of what the project would look like in my head

#

i realized that the maintenance cost of this would be astronomically high on complex projects

#

the programmers having to dig through editor serialized reference chains

#

having to debug giant unreadable stacktraces

#

no validation can save you from design time errors

ashen yoke
heady iris
#

somewhere

#

what, you want more information? die

#

well, that's more of a [SerializeReference] problem :p

heady iris
#

for example, I replaced my "player stat" enum with scriptable objects

#

the one problem is that I can no longer just say Stat.Health

#

however, it turned out that there were very few places that it was reasonable to hard-code that (e.g. checking if you are dead)

silver gulch
#

Hi, so I want to save & load any replays which are made in the game. the replay mode already works, and there are no issues in the editor. but as soon as I try to save or load in the build game, the game crashes at the point I click. does anybody maybe know the reason? thanks!

btw: this is for my game Unity Flight Simulator with over 4.5k downloads, and It would be very nice, if I can implement that save & load function

heady iris
#

so I just gave each entity a list of stats that, if they hit zero, cause death

silver gulch
#

that sucks

ashen yoke
#

i.e. the scriptable holds serialized stats, simple pod with float fields

#

on runtime the user stat class simply reads it and initializes

#

so that is not direct hooking of SO as a data ref

#

there are a few places where this is more beneficial, for example when user class is volatile

#

i only have to ever edit the init method where the stats are populated with values, but i dont have to keep them in any way synced or coupled

silver gulch
# silver gulch Hi, so I want to save & load any replays which are made in the game. the replay ...
sonic zinc
#

private IEnumerator shootAtPlayer()
{
LeftShoot();
yield return new WaitForSeconds(6f);
RightShoot();
yield return new WaitForSeconds(6f);
Debug.Log("coroutine finished shooting");
}

This code makes the left gun shoot a ton of times and then makes both of them shoot a ton. I want the left gun to fire once and then wait 6 seconds, then the right gun fires once and wait 6 seconds. Im still kind of new to using IEunmerators.

ashen yoke
#

and that serialized stat block is a class, so can be embedded anywhere

leaden ice
ashen yoke
leaden ice
#

If it's firing multiple times you're probably running the coroutine many times

sonic zinc
#

startcoroutine just continues it if its aleady running I thought

leaden ice
ashen yoke
leaden ice
#

What else would it do

sonic zinc
#

I see it used a lot, I thought it was just the only way to start a coroutine

timid crater
#

Evening, is it possible to paste a gameObject inside multiple different parents?

sonic zinc
#

is there a different method

silver gulch
ashen yoke
leaden ice
ashen yoke
#

or track existing coroutine

leaden ice
#

Why would there be another way?

fervent furnace
#

You need to not start coroutine if your previous coroutine unfinish

leaden ice
#

If you don't want to start another coroutine, don't call it

ashen yoke
#

somewhere there can be a solution

sonic zinc
#

this coroutine is supposed to be used if the player gets in vision of the enemy, 6 seconds is just a ridiculous number for testing purposes. how can I check if the coroutine is running and not start it if it is?

leaden ice
#

And stop it when it leaves

#

It doesn't need to go in update

ashen yoke
#

hed need a while loop there

leaden ice
#

If you want to repeat code that's why god invented loops

#

Or Moses, or whoever it was

ashen yoke
#

K&R

#

probably

leaden ice
#

Definitely think it was Moses

ashen yoke
#

40 years to hit a break?

#

i dont know about what is a sensible joke here

#

dont judge

sonic zinc
#

I got it work properly, thanks everyone. I just did something llike this
if (!currentlyShooting)
{
StartCoroutine("shootAtPlayer");
}

ashen yoke
#

dont forget to stop it

#

also dont use string

#

just pass the method directly

#

StartCoroutine(ShootAtPlayer());

unreal valley
#

Question. Im going to run into a problem if I have the leveling system on the ScriptableObject Job aint I?

ashen yoke
#

eventually maybe

#

is it a hard dependency?

sonic zinc
unreal valley
ashen yoke
sonic zinc
#

got it

ashen yoke
unreal valley
#

Suppose its just data at this point

ashen yoke
silver gulch
#

yeah, there was no error before crash

#

now I am trying to use using System.Windows.Forms;

#

if that doesnt work, then I know that this isnt the issue

knotty sun
unreal valley
#

I could pull it out into its legit own system and make List of this data based on the jobs. idk.

ashen yoke
#

if its just a data object you embed into another its fine

silver gulch
ashen yoke
#

if by design they are supposed to come together

#

you are simply abstracting reusable data blocks into classes so you can compose various data objects

gray mural
#

what's KeyCode of the button that is called "End" and located at the bottom right corner on the laptop near "PgUp" and "PgDown"?

knotty sun
silver gulch
ashen yoke
#

that StandaloneBrowser is a native lib

silver gulch
knotty sun
gray mural
heady iris
#

that is...not the end key

knotty sun
gray mural
ashen yoke
#

click on KeyCode, press F12

gray mural
#

<- Home
-> End

knotty sun
heady iris
#

maybe if you have one of those small keyboards

#

that requires a function key to be held to get certain keypresses

silver gulch
#

Okay, the System.Windows.Forms works, but it looks weired af

gray mural
heady iris
#

yes, that's your specific keyboard

#

that will not work for everybody

gray mural
#

ok then

heady iris
#

or did you want the right arrow key?

gray mural
silver gulch
heady iris
silver gulch
#

good, now I want to get the normal explorer and not that crappy thingy

heady iris
#

most keyboards don't overlap the two

gray mural
# heady iris but not **the** end key

yes, I was wondering why this code was not working 🙄

if (Input.GetKeyDown(KeyCode.End)) audioSource.time += secondsRemote.home;
else if (Input.GetKeyDown(KeyCode.Home)) audioSource.time -= secondsRemote.end;
ashen yoke
#

that looks like the ui toolkit unity uses without its unity skinning

heady iris
silver gulch
#

isnt there a way to make it look good

silver gulch
ashen yoke
#

afaik it was gtk 2

silver gulch
ashen yoke
#

unity ui is using it

marsh hawk
#

I'm trying to make splash damage in a 2d game, but the projectiles aren't doing damage. I've figured out that it isn't making it to the code in the red square, but I don't know what it is beyond that. However, a problem might be that, despite the fact that the Bullet script (second one) should be setting the damage to 10, it stays at 0, which might be related.

dusk apex
#

Or if the if-statement is true at all.

#

How to post !code

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.

marsh hawk
dusk apex
#
Debug.Log($"{name} hit {collider.name} that had a layer of {collider.gameObject.layer}");```
#

If this is false, nothing else would matter.

#

Collapse log if you're getting a great amount of spam.

marsh hawk
#

ok

harsh bobcat
#

if two threads try and add an element to a global list at the same time do both go through?

harsh bobcat
heady iris
#

you probably aren't using threads

dusk apex
#

Ensuring you're simply not misunderstanding stuff.

harsh bobcat
#

im modifying a tool that loads assets asynchronously

#

not 100% sure on the execution but I do know my code continues to run while the assets are in the process of loading

#

and I can subscribe functions to the OnLoaded event of individual bundles

dusk apex
#

There will be race conditions. Do not expect anything to be in any order.

harsh bobcat
#

order I dont mind as long as both get added to the list

#

my concern was something like both threads access a 9 length list and change length to 10, setting the 10th element at the same time

#

losing an entry

#

alternatively I can just have a void LoadNext run each time OnLoaded gets sent and force it to be synchronous

#

nvm I can just make it a dictionary, so no two threads should ever access the same key

ashen yoke
heady iris
#

i'm not sure if a dictionary would behave properly

lunar lynx
#

how do I create a new key-value pair in my dictionary, where the value needs to be an array of a class?

    Dictionary<string,ConnectedPieceClass[]> allConnectedPiecesDic = new Dictionary<string,ConnectedPieceClass[]>();

having trouble on the line below

                allConnectedPiecesDic.Add(kvp.Key,new ConnectedPieceClass()[]);
heady iris
#

arrays have fixed lengths, after all

lunar lynx
#

😠

heady iris
#

perhaps you want a list instead

lunar lynx
#

yeah, a list

#

ok brb

#

thank you!!!

buoyant arrow
#

please ping me with response
I’m new to Unity and I have a few troubles.
I have a camera that can be moved with a rigid body, and two spheres. One sphere has a lens flare and lights component.
I want the camera to be able to move through the spheres, so I disabled sphere colliders. However, now the lens flare and light pass through the sphere without those components. Is there a way to have a sphere that lets a camera pass through it but not light/Lens flare?

harsh bobcat
vagrant blade
buoyant arrow
#

I’ll look into that—thanks!

ashen yoke
#

im loading prefab for editing with PrefabUtility.LoadPrefabContents
then trying to attach another prefab with PrefabUtility.InstantiatePrefab and passing loaded root transform as parent
then PrefabUtility.SaveAsPrefabAsset and nothing, checked with debugger, prefab reference is not null

#

nothing i mean the prefab is saved, but the instantiated one is not attached to it

vale wren
#

anyone know how to make a card scrolling system that looks like you're scrolling along the side of a cylinder if that makes sense

#

my idea is to render cards in 3d space along the edges of a circle but prob overthinking it

ashen yoke
#

huh apparently PrefabUtility.InstantiatePrefab "parent" argument does nothing in this case, have to explicitly SetParent

heady iris
#

🫠

buoyant arrow
static matrix
#

will this work as anticipated, quickly creating a Time.Deltatime timer (+1 each second)

somber nacelle
#

no, you shouldn't be calling MonoBehaviour constructors manually

#

what is the purpose of this?

static matrix
#

idc will it work

#

to make setting up timers quicker

somber nacelle
static matrix
#

you said I shouldn't be making them manually, not whether or not it would make a timer

#

nvm

#

ill do this the other wat

#

*way

mossy snow
#

Timer.Update will never be called since you create Timer incorrectly like boxfriend says

static matrix
#

ahhh

#

ok

somber nacelle
static matrix
#

thank you for answering the question

static matrix
somber nacelle
#

sorry, i assumed we were in #archived-code-general and i wouldn't need to explain every little detail about why you shouldn't be calling a monobehaviour ctor

cerulean oak
#

where should I backup the save to the cloud? I want it to be synced up with the PC version, so I want to do it often enough, but I dont want to bloat the database by sending saves every minute.
Also I dont want a save button, currently the state (locally) is saved on specific events

somber nacelle
#

how often do those events trigger to cause a save to happen?

cerulean oak
#

like once every 3min

#

maybe

somber nacelle
#

then why not backup to cloud then?

cerulean oak
#

idk, firebase seems expensive xd

#

1$ per gb downloaded

#

well

#

you are right, my problem is not the backup frequency

#

my problem is that currently the save can get very chonky

somber nacelle
#

how are you currently serializing the data to be saved? and how much of that data actually needs to be saved in the first place?

cerulean oak
#

json

#

and the data can be a few hundred kb after a few weeks of use

#

after minifying I can get it to 1/3rd

somber nacelle
#

ah yeah, that'll be chunky. could always look into something like messagepack, it's pretty good about creating nice and small binaries. can even use compression too

cerulean oak
#

are protobufs ok for serializing persistent data?

somber nacelle
#

i've never used it but i don't see why not. message pack is typically smaller and faster than protobuf though

cerulean oak
#

I use them at work

#

but for messaging

fluid imp
#

Hey guys, so I'm just writing up a player and camera controller however something happened to then led to this lol, anyone might have a clue to what has caused this? The camera isn't even centering on the target for some apparent reason.

cerulean oak
#

message packs seem very neat tho, since you go directly from json to them

#

also, big part of the bloat in my json are DateTime objects, that get serialized as strings "2023-05-07T11:19:00"

#

could probably serialize them as a long, if I switch to messagepacks

somber nacelle
#

i think by default messagepack also serializes datetime as strings, but you can use the nativeresolver instead
same for GUID and decimal

cerulean oak
#

yeah I mean I could just serialize them as a property that is DateTime.Ticks

fluid imp
rugged storm
#

Hay in my script i set MoveEndTile as a refrence to a Tile object, but later i want to set it back to a reference to null, how do I do this without setting the tile object its refrencing to null?

heady iris
#

you want to make it null

dusk apex
heady iris
#

but you don't want to make it null?

rugged storm
#

i dont want to make the object null I want to make the variable null

heady iris
#

then assign null to the variable

#

i don't get your question

dusk apex
#
transform.position += moveDir * moveSpeed * Time.deltaTime;```
Move direction is a quaternion. Why are you adding it to the Vector3 position?
rugged storm
#

I was accidentally also running SetActive("false") on the object

heady iris
#

obj.SetActive(false) (not "false") would make the game object inactive

rugged storm
#

IK i wrote it incorrectly there my b

fluid imp
rugged storm
#

also i just noticed the event trigger "pointerdown" detects right, left and even middle clicks how do i specify what type of click? should add like an

 if(Input.GetMouseButtonDown(prefmousebutton))```? or is there a way to do it from within the inspector in the event trigger component?
primal wind
#

It should take an int as a parameter

hasty haven
#

Are playerprefs concidered acceptable for storing game settings?
I dont have much to worry about other than some common int values and booleans

heady iris
#

that's what they're there for

#

prefs, stored by the player (rather than the editor)

#

(even though player prefs work in the editor)

hasty haven
#

Mmk, i made a custom save system for other things that uses its own file format and obfuscation. Sounds good

rough horizon
hasty haven
#

That might be overkill for settings though, i need to get this ready asap for deadline

#

Mmk thanks. It seems like window settings like resolution and mode persist so im not storing those

primal wind
hasty haven
#

Our game has a lot of unlocks and progress checking so i'm handling that without prefs lol

rough horizon
#

As for me, I'm tryna start the whole 'health' and 'take damage' system for my game.
I suppose I need an entity that deals damage (example, sword hitbox, or pitfall trap), and one that takes damage (player, enemy, or even wooden crates).
I guess what I need is, vague pointers on whether to use interfaces, class inheritance, or child gameobjects, etc.

hasty haven
# rough horizon As for me, I'm tryna start the whole 'health' and 'take damage' system for my ga...

What i like to do is have a script on players and enemies alike called CharacterAttributes that has common values like health, and what type they are "Player, Neutral, Enemy" and on that method have a public void TakeDamage(DamageInstance d); where DamageInstance is a struct that has whatever values you need like damageType, damageValue or even a reference to who the damage came from.

If you like inheritance and want to treat enemies differently, you could make EnemyAttributes which inherits from CharacterAttributes and overrides those methods like TakeDamage

#

You could also just use a simple number instead of damage structs, but i like to include context data so you can handle things like lifesteal and heal the owner

open shard
#

I have a situation in my game where there is a central hub with several portals. Then there are other scenes where the player must do some actions to unlock the portals. While the player is in such a scene, the hub scene is unloaded. How can I make a system where an event is invoked when the player unlocks the portal and then the portal opens once the main hub is loaded again? e.g. changing the material of the portal

rugged storm
dusk apex
#

Not certain then, it shouldn't cause you to be teleporting around the area.

rough horizon
# hasty haven What i like to do is have a script on players and enemies alike called Character...

I think I want to avoid inheritance, notably because the player and some more complex enemies already inherit from StateMachine in my case.
But yeah now that I think about it, player taking damage and enemies taking damage will probably behave drastically differently... in terms of knockback, iframes, animations, statemachine etc.
maybe i'll just do an interface, since they won't have any underlying logic in common beyond "take damage" method.

rugged storm
#

okay i think i figured it out, i need to pass PointerEventData into the method that gets called then check that

#

NM if i try to do that, the event trigger does not recognize the method exists

hasty haven
heady iris
#

i've found that to be a really nice model

#

you just write it Once

molten thicket
#

Hey guys,

I'm a bit stuck trying to get the formatting for a number correctly,

I pull a value from a server, say something like 5000000.

The number I fetch has 6 decimals, so that number above might only be 0.00005, however Unity doesn't show that?

I've tried string.format() and a few other tricks, but I can't seem to dynamically add the . if the value is less than 1.

Would anyone be able to give me a bit of direction?

Thank you!

sour zealot
#

I made an airlock door system that im very proud of
but the big problem is
that the box collider that triggers the door when a player goes near it
I have an aim transform
that goes wherever my aim transform points
and the aim transform doesnt go through the box collider trigger which I want it to

rough horizon
#

and if you need to sometimes render a decimal and sometimes not, i'd probably actually just write an if statement.

molten thicket
rugged storm
heady iris
#

OnPointerDown will pass a parameter of this type

#

you must already have it, or you'd get an error

rugged storm
#

Im using the event trigger component

heady iris
#

wait, sorry, that's UIElements

#

bah

#

show your code

rugged storm
#

k 1 sec

somber nacelle
heady iris
#

yeah, there's the one I wanted

somber nacelle
#

yeah UI docs have been split into a separate area for whatever reason. i had to bookmark it because any other time i try to find them i only come across the old ones on the regular docs site

heady iris
#

does this one actually tell you which mouse button was pressed?

#

ah, there it is

#

button

rugged storm
somber nacelle
#

you should be able to accept PointerEventData as a parameter for those methods

#

then they'll show up in the Dynamic section when selecting a method to add a listener for

sour zealot
#

box

#

mind answering my question?

somber nacelle
#

depends entirely on the question

somber nacelle
heady iris
#

hm, it says BaseEventData in the unity events in the inspector, tho

sour zealot
# somber nacelle depends entirely on the question

I made an airlock door system that im very proud of
but the big problem is
that the box collider that triggers the door when a player goes near it
I have an aim transform
that goes wherever my aim transform points
and the aim transform doesnt go through the box collider trigger which I want it to

heady iris
#

do you have to receive a BaseEventData and then downcast that to PointerEvenData? that sounds weird

sour zealot
#

oh and I fixed the whole thing

rugged storm
#

if i attempt to accept PointerEventData with the method it simply does not show up in the inspector

sour zealot
#

the thing yesterday

#

i fixed it

rugged storm
somber nacelle
somber nacelle
rugged storm
#

I can accept base event data, it shows up under the dynamic section like you said

somber nacelle
#

then you should be able to cast using the as keyword (or if you are using a modern unity version you could even use is in an if statement)

heady iris
#

i.e. var data = baseData as PointerEventData;

#

it seems weird that it'd go this way...

somber nacelle
#

if(nameofparameter is PointerEventData pointerData)

rugged storm
#

Ah okay

somber nacelle
# heady iris it seems weird that it'd go this way...

it's probably because the events are just stored in a list of EventTrigger.Entry and it has to support all of the events so using the base class for the event data would be necessary for that type to support all of them

sour zealot
#

i forgot to send the image

heady iris
#

downcasting my unbeloved

sour zealot
#

the green thingis the aim transform

rugged storm
#

think it worked with a

        var pointerdata = baseData as PointerEventData;
        if (pointerdata.button == 0 )
        {//stuff
#

ty yall

sour zealot
heady iris
#

to be more readable, you should use PointerEventData.InputButton.Left

sour zealot
#

this is the box collider

#

lmk

somber nacelle
#

i still don't know what you mean by "the aim transform doesnt go through the box collider trigger"

heady iris
rugged storm
#

kk

heady iris
#

is that circle winding up in the wrong place?

vapid bough
#

does anyone know why i have to change external script editor to visual studio every time I launch

heady iris
#

are you quitting unity normally?

#

rather than, say, having it crash

somber nacelle
#

you shouldn't have to change it every time. if you are quitting normally and it still resets every time, try launching unity with admin perms and set it then restart it as non-admin

desert shard
#

I quit unity every day mentally

somber nacelle
#

are you really even using unity if you haven't mentally quit at least once an hour

desert shard
#

this was a painful day

heady iris
#

added bad voxel meshes

#

for a giggle

sour zealot
somber nacelle
#

by ignore the collision do you mean prevent OnTriggerEnter from being called, or do you mean it is actually physically colliding with the trigger collider

#

either way this should be useful: https://docs.unity3d.com/Manual/LayerBasedCollision.html
however if there is a physical collision happening with a trigger collider then either the collider isn't actually a trigger or you are using physics queries to determine where the object can move to but not filtering out trigger colliders

idle crow
#

Is the animators locked in sync with the update or fixedupdate? I have code running for hitboxes, and movement that is locked into set numbers, should I excute it in the fixed update, or will it be fine in the normal update loop? Just unsure about how code runs in tandem to animations

heady iris
#

animators update every frame

heady iris
#

by default, at least

#

there is indeed a setting

idle crow
#

Will changing it to animate physics change the quality of the animation at all seeing as it would be a fixed 50fps?

leaden ice
#

probably

heady iris
#

what is "movement that is locked into set numbers"?

idle crow
somber nacelle
#

then either the collider isn't actually a trigger, or like i mentioned you may be moving based on raycast (or other physics query) hits and not filtering out trigger colliders

molten thicket
#

Hey guys!

One more quick question,

Is it possible to parse a BigInteger into a float? 🙂

sour zealot
leaden ice
#

probably not a good idea in general since BigInteger can hold much larger numbers than float can with any degree of accuracy

somber nacelle
heady iris
molten thicket
heady iris
#

perhaps you are getting a trigger event and stopping the bullet in response

sour zealot
heady iris
#

i still don't understand what your "aim transform" is

#

it's not the bullet?

#

is it something that you're positioning with a raycast?

sour zealot
#

yes

heady iris
#

then tell the raycast to 1) ignore the layers it shouldn't hit 2) ignore trigger colliders

sour zealot
#

where would I put the exclusion

heady iris
sour zealot
heady iris
#

no

sour zealot
#

oh

heady iris
#

read the documentation.

desert shard
#

thrice.

heady iris
#

you must make the effort to read what's being shown to you.

sour zealot
#

what does this mean: QueryTriggerInteraction queryTriggerInteraction = QueryTriggerInteraction.UseGlobal

heady iris
#

this is the default value for that parameter

#

the parameter's type is QueryTriggerInteraction, and the parameter is named queryTriggerInteraction

#

the default value is QueryTriggerInteraction.UseGlobal

sour zealot
#

oh

#

so QueryInteractionTrigger.Ignore

heady iris
#

correct

#

you should also be passing a layer mask so that your raycast only hits things that make sense

#

i.e. the map and enemies, probably

sour zealot
#

yeah

#

do you know of a good way to acomplish a brawl stars like matchmaking system with netcode

#

if u even know what that is

heady iris
#

idk about the netcode aspect

#

i'd expect matchmaking to just be a server that people tell "hey, I want to play", and that then later tells the clients when it's found a match

#

bit of a large question to ask, though

desert shard
#

multiplayer is so insane to develope it hurts

heady iris
#

it is Additional Work (tm)

#

i have a little experience

desert shard
#

Don't do it

#

unless you're doing it with others

#

in a professional setting

#

else pain

vapid bough
#

is it ok to have both rigidbody and character controller on the same gameobject?

hard sparrow
#

Trying to get OnDrop to work consistently is insanely frustrating

#

Sometimes it works, othertimes you'll drop something right on it and it won't count

#

Is it based on your mouse position or on the object you're dragging?

heady iris
vapid bough
#

not any .addforce shenanigans

heady iris
#

you can already get .velocity from the character controller

vapid bough
#

thats a thing?

#

oh wait its read only i need to write to it as well

heady iris
#

what are you trying to do here? the character controller is used explicitly to avoid having a physically-simulated player

#

it respects colliders, but it doesn't get affected by physics forces

vapid bough
#

idk i just need to sync the velocity between server and client

#

and this is the simplist solution i thought of

heady iris
#

uh

somber nacelle
heady iris
#

i've been having a good time with the KCC so far

vapid bough
#

tbh didnt know it was a thing

heady iris
#

i'm making a low poly first person movement shooter

#

[daring today, aren't we?]

vapid bough
heady iris
#

buddy

#

you're writing a multiplayer game

vapid bough
#

yes

heady iris
#

you're gonna have to get used to this

vapid bough
#

and im still lazy

heady iris
#

then you are not writing a multiplayer game

vapid bough
#

i had to remake it from scratch again because netcode was a pain in the ass

#

il look at the kcc

uncut plank
#

Im attempting to make a function that i can use to change the FOV of the camera, but for the FOV to lerp smoothly i need to keep the * Time.deltaTime at the end. However this crashes unity. How might i get around this. I have tried making a Coroutine instead but when i do that its rlly buggy and the FOV never truly hits the targetFOV and just kinda sits in between the two values and buggs out

#

Here is the Coroutine i attempted to create instead

dusk apex
#

The first is an infinite loop that would crash the Unity Editor application

#

Your lerp is incorrect in both.

somber nacelle
#

your current parameters would be better with Mathf.MoveTowards instead of Lerp since they are not currently linear

dusk apex
#

If you do not need to traverse in reverse, I'd suggest simply adding steps in delta.

#

Smooth damp can create dampening if you need damping.

uncut plank
dusk apex
uncut plank
#

oh shit

#

how do i make it proper

somber nacelle
#

and if you do, it's really only because of floating point inaccuracies

uncut plank
#

damn thats prob been my problem the whole time

#

or A problem

dusk apex
#

I suggest simply not using lerp and simply using move towards unless you're needing to traverse backwards

uncut plank
#

wdym by traverse backwards

dusk apex
#

Same thing but requires less setup

uncut plank
#

cause i change the fov from like 75 to like 90 and back to 75 if thats what u mean

dusk apex
#

Lerp's third parameter isn't how much to move this frame. It's where you are in the linear interpolation.

#

Where 0 is at the initial position and 1 would be at the final position.

#

Where your first argument would be a copy of the initial position - not your current position. The second argument would be your final position.

#

The improper way to lerp has folks using current position as the first argument and some fraction as the third argument.

#

For example, if the third argument is 0.5f you'll simply reduce the distance between you and the target by half each call but you'll never be at the target ever (you'll never have a progress of 1.f).

dim hill
#

I'm having issues with my car's wheels wobbling around alot when im driving. I am using a wheel collider. What could be causing this?

It doesnt seem to be the collider that is wobbling because the car isnt affected but the meshes sure do look strange

Heres the code for each individual wheel:

    { 
        if (Input.GetAxis("Vertical") <= 0)
        {
            wcol.brakeTorque = Input.GetAxis("Vertical") * brakeForce;
        }
        if (Input.GetAxis("Vertical") >= 0)
        {
            wcol.motorTorque = Input.GetAxis("Vertical") * power * -1;
        }
        if (steering)
        {
            wcol.steerAngle = Input.GetAxis("Horizontal") * steeringRatio;
        }
        

        Vector3 pos = transform.position;
        Quaternion rot = transform.rotation;

        wcol.GetWorldPose(out pos, out rot);
        wtra.transform.position = pos;
        wtra.transform.rotation = rot;
    }```
steady moat
dim hill
#

Yeah

steady moat
#

Try using a sphere instead.

#

Does it interact with the model of the car ?

#

Try to disable collision between them.

dim hill
#

No, the part that is wobbling is just a mesh and has no physical impact on the rest of the car.

steady moat
#

So, the collider is correct ?

dim hill
#

Yeah the collider is all good

#

it just looks very odd

steady moat
#

I feel like this is really a question of pivot.

#

Try a sphere

dim hill
#

Alright will do

#

one second

#

It is perfectly smooth with a sphere

#

so that means my wheel model is dodgy?

steady moat
#

Yes, it probably means the the pivot is not in the center or the model is not symmetric.

dim hill
#

I think this may be my issue in blender, the cursor is not at 0,0 which is where the centre of my wheel is.

steady moat
#

Is the wheel really symmetric ? You may have made a mistake. Try to export a sphere.

dim hill
#

oh yeah you are right, this is what it looks like when mirrored

#

ill just make a new wheel lol

#

thanks for the help 😃

heady iris
#

wiggly

marsh hawk
#

How would I make particles stay after the particle system's parent has been disabled? I can't find something I can use online

heady iris
#

the particle system renders the particles

#

so, you ain't gonna disable that without losing the particles

#

what are you trying to do? stop spawning particles?

marsh hawk
heady iris
#

i would just stick the effect on a separate game object

marsh hawk
#

I don't think that would work well since it's in an object pool and there are multiple instances of the object

heady iris
#

sure, spawn several instances of the effect.

#

i guess you could also pool the effect objects, if you really wanted to do that

marsh hawk
#

I'll try, gimmie a sec

river saddle
#

I have an issue with Rigidbody2D.Addforce, where it's acting basically as .velocity. In my game it's supposed to be for a jump feature but for some reason it isn't working. I've haven't had this issue before. When I press the button to jump and the jumpHeight is over 20, it increases velocity.y far beyond where it's supposed to go and caps out at 5000, this is all I have to make it jump (Other than the calling of the function).

void Jump()
{
rb.AddForce(new Vector2(0, 1) * jumpHeight);
}

river saddle
#

I've tried, same result

#

I initially had it as impulse

cosmic rain
#

Are you calling it every frame?

cosmic rain
#

Probably your movement and jumping logic mess up each other.

near coral
#

Hey guys, so I'm making this retro style game and need the animations to look choppy like 1-2 frames. I've created scripts to enable one image and disable the other but the problem with my game is that it consists of a series of canvases rather than scenes so the animation is in a canvas that will be activated later in the game but regardless, the animation plays when the game loads at the start because it's not hooked up to a button or anything, I just want it to play when the canvas is enabled, but with a delay.

cosmic rain
near coral
#

Yea my game is just a 2D point and click adventure so I just used canvases. I tried to make it play on Awake but that also didn't work because I all the canvases are loaded at the beginning and then disabled and reenabled one by one.

#

So it thinks that it should play at the beginning

#

But I thought that it should still reset and then work when it's awoken again?

cosmic rain
cosmic rain
#

From the sound of it, you just swap sprites manually. That wouldn't reverse/reset unless you tell it to.

near coral
#

Oooh ok thanks I just need to reverse it

near coral
sonic zinc
#

private IEnumerator SteppedOn()
{
yield return new WaitForSeconds(2f);
if (Physics.CheckSphere(transform.position, outerExplosionRadius, playerMask))
{
playerHealth.ReceiveDamage(15);
if (Physics.CheckSphere(transform.position, medialExplosionRadius, playerMask))
{
playerHealth.ReceiveDamage(20);
if (Physics.CheckSphere(transform.position, innerExplosionRadius, playerMask))
{
playerHealth.ReceiveDamage(50);
}
}
}
Destroy(gameObject);
}

trying to make a landmine. right now it only does 15 damage even if Im in the inner circle

leaden ice
#

Why not just use Vector3.Distance once

sonic zinc
#

I got it to work thanks to chatgpt, I just cant execute playerhealth.receivedamage that much

#

and I didn't think of vector3.distance, still not used to game programming but that is a good idea

#

I thought about it too literally lol

wise beacon
#
    {
        if (other.tag == "Grape")
        {
            Destroy(other.gameObject);
            health += 0.1f;
            healthbar.SetSize(health);
            count++;
            countText.text = "count: " + count.ToString();
        }
        if (other.tag == "Bannana")
        {
            Destroy(other.gameObject);
            health += 0.1f;
            healthbar.SetSize(health);
            count++;
            countText.text = "count: " + count.ToString();
        }
        else if(other.tag == "Donut")
        {
            Destroy(other.gameObject);
            health -= 0.1f;
            healthbar.SetSize(health);
        }```

I'm trying to have the character destroy the item labled "Bannana"
I've had the "Grape" work, however the "Bannana Item wont disappear after the player touches it. I'll need to respell banana.
dusk apex
#
Debug.Log($"{name} hit {other.name} that had a tag of {other.tag}");```
#

Have the logs on collapse if you're receiving too much spam from the console.

calm talon
#

The same save file being used between the built version of my game and the editor ends up producing different results when loaded though I'm not entirely sure why

#

The code that loads the file:

public void LoadGame()
    {
        GameData data = Save_Load.Load();
        Player_Settings settings = Save_Load.Load_Settings();
        if (data != null && settings != null)
        {
            transform.position = new Vector3(data.RespawnPos[0], data.RespawnPos[1], 0);
            HP = data.PlayerTotalHP;
            CurrentHP = HP;
            shot_controller.has_gun = data.has_gun;
            shot_controller.has_shotgun = data.Has_Shotty;
            if (data.Has_Shotty == true) GameObject.Find("Shotgun Acquire").transform.position = new Vector3(600, 600, 600); 
            QuarterHpPickups = data.QuarterPickups;
            Checkpoint.x = data.RespawnPos[0];
            Checkpoint.y = data.RespawnPos[1];
            Checkpoint.z = data.RespawnPos[2];
            int x = 0;
            foreach (Cutscene_Control script in FindObjectsOfType<Cutscene_Control>())
            {
                script.HasBeenTriggered = data.CutsceneTriggers[x];
                if (data.CutsceneTriggers[x] == true) script.MoveCamera();
                x++;
            }
            int a = 0;
            foreach (Upgrade_Behaviour upgrade in FindObjectsOfType<Upgrade_Behaviour>()) 
            {
                upgrade.Taken = data.upgrades[a];
                upgrade.Move();
                a++;
            }
            int z = 0;
            foreach (ReceptacleAndBall receptacle in FindObjectsOfType<ReceptacleAndBall>()) 
            {
                if (data.triggeredEnvironment[z] == true) receptacle.Activate();
                z++;
            }
            int y = 0;
            foreach (BaseBossBehaviour baseClass in FindObjectsOfType<BaseBossBehaviour>()) 
            {
                if (data.bossKills[y] == true) baseClass.Die();
                y++;
            }
        }
    }```
dusk apex
#

May want to inform folks how they differ in detail so people have got a clue what to look for rather than just simply looking for a mistake that may not exist.

calm talon
#

Say I have 2 instances of the Upgrade_Behaviour script and I collect the first before saving in the editor

#

if I were to load, the first would be taken, the second is untouched

#

however if I were to use the exact same file that I saved from the editor in the built game

#

loading would cause the first to remain and the second to be taken

#

and vice-versa for if the save were made in the build and used in the editor

dusk apex
#

Main difference between build and editor would be folder/file structure.

#

Maybe the save isn't present for the build.

calm talon
#

Same saves for both

dusk apex
#

Is the path dependable?

#

If you're just saving to the root, the build will not have the save file.

calm talon
#

same path for both

dusk apex
#

The information is missing thus why I'm asking

calm talon
#

specifically it uses the persistent data path bit

dusk apex
#

Without looking more into the code above, would the game load the second if no save files were present?

calm talon
#

nope

dusk apex
#

So when does the game load the first?

calm talon
#

oh wait

#

It can't load at all

#

it would throw an error since it can't find a file

dusk apex
#

Well, relative to the code above.. this would be the only section related to upgrade behavior: cs int a = 0; foreach (Upgrade_Behaviour upgrade in FindObjectsOfType<Upgrade_Behaviour>()) { upgrade.Taken = data.upgrades[a]; upgrade.Move(); a++; }

calm talon
#

data is referenced from de-serializing the save file, if that's null then this block never gets run

dusk apex
#

Why explicitly FindObjectsOfType rather than FindObjectsByType?

#

It is recommended to use Object.FindObjectsByType instead. This replacement allows you to specify whether to sort the resulting array. FindObjectsOfType() always sorts by InstanceID, so calling FindObjectsByType(FindObjectsSortMode.InstanceID) produces identical results. If you specify not to sort the array, the function runs significantly faster, however, the order of the results can change between calls.

calm talon
#

I didn't know the other existed

#

Though I rely upon the assumption that everytime I call that function

#

the resulting array of objects that's returned is always in the same order

dusk apex
#

You're going to have to attach the debugger to the build and log data from the data upgrades.

#

Likely the data isn't what we're expecting or there's some sort of race condition elsewhere.

#

This code won't likely change itself.

calm talon
#

Race condition?

dusk apex
#

I've got no other suggestions as I've only seen this method

calm talon
#

so could it be that there's differing instance IDs between the editor and build?

#

I have had this exact code work in the past and I haven't changed anything in regards to those objects being accessed by other scripts

#

Because assuming a build made save is used in the build and the same for one made in the editor

#

it remains consistent and I can't observe any odd behaviour

lyric panther
#

I want to give a script a component and then i want to be able to choose a void to trigger from the editor. how would i do this?

cosmic rain
#

UnityEvent..?

lyric panther
#

Yes! thank you

cunning meteor
#

how does this not work

simple egret
#

Your parameter is called collision, not other

cunning meteor
#

thanks

simple egret
#

Also you should use CompareTag, it's more performant and warns you if the tag doesn't exist.
if (collision.CompareTag("collectable"))

sterile grail
#

I'm currently procedurally generating 25 islands and storing the positions of every single block being used to make up the islands so that I can instantiate scenery etc. So far it works fine but now I need to find a way to track each 40x40 island so that I can individually reference them instead of just referencing a single block within them. My current code is as follows: https://gdl.space/ravotidije.cs I've added a few comments to make it easier to see what I was going for but I'm stuck with an error telling me I can't convert a list to a Vector3 (which will be due to the way I'm trying to store the islands). Could someone take a peak and give me some pointers on what I should be looking at trying? Cheers

high current
#

I'm not sure if any snippets of code are needed, but I'm currently using object pooling just to learn how to and my current project is a sort of sorting game where I press a number and drop an item into a box where the item gets set inactive to put it back into the pool to be reinstanciated. However, I'm running into an issue where when I call a game object such as a sphere with object pooling, they seem to carry their momentum from when they were first called. I.E the Sphere got booped and now has momentum towards the right, when that object gets called again to be dropped straight down, it'll carry the momentum from when it got hit to the right. Is there a way I can reset the momentum or would I have to have force on the rigidbody with a normalized speed pushing it straight down to achieve the desired goal?

bright relic
#
                    vertices[v + 1] = new Vector3(vertexOffset, heightValue, vertexOffset) + cellOffset + gridOffset;
                    vertices[v + 2] = new Vector3(vertexOffset, heightEast , -vertexOffset) + cellOffset + gridOffset;
                    vertices[v + 3] = new Vector3(vertexOffset, heightEast, vertexOffset) + cellOffset + gridOffset; ```
    im trying to add a 0,125 bezel to my mesh generator, i've tried 
```cs heightEast + 0,125```
 but the problem is that with my current code im using the same formula if the height destination is either higher or lower and adding a constant in this way doesnt work in both directions
high current
regal violet
#

Hello guys, is it possible to create Input in play mode test for testing the behavior of my characters responding to the user inputs ?

calm talon
#
    private void Reset()
    {
        Restart:
        id = Random.Range(-32000.0f, 32000.0f);
        foreach (Upgrade_Behaviour upgrade in FindObjectsByType<Upgrade_Behaviour>(FindObjectsSortMode.None)) if (upgrade.ID == id && upgrade != this) goto Restart;
        identity = id;
    }

is there any way to get this code block to run whenever I drag in an instance with the class attached?

#

such as through dragging in a prefab with the class attached to it

#

Obviously Reset isn't the right function for it

swift falcon
#

does anyone know how rust does this?

mellow sigil
#

Which part of that picture is "this"?

simple sable
#

Hi guys.

Can anyone help me figure out how I can lower the speed at which one of my game objects moves based on how close it is from its the target position?
Like, the object moves towards a target position with speed 5, but I would like to have it slowly go to 4 the moment the distance between the object and the target position is lower than 1.5f or something.

swift falcon
#

like

#

when they go into the inventory they show a version of the character model so when you equip the armour it shows it on the character

calm talon
mellow sigil
swift falcon
#

alrighty

agile tulip
#

Howdy all! A bit of a newbie question here: How can I add/declare a list inside my class list?

public class TargetClass
    {
        public GameObject targetGameObject;

        public TargetClass(GameObject _aiGameObject, // List for waiting)
        {
            targetGameObject = _targetGameObject;
            // here a list for waiting
        }
    }
    public static List<TargetClass> targetList = new List<TargetClass>();
sterile grail
# dusk apex Show us the actual error.

Sure, here it is: Assets\GenerateGrid.cs(63,41): error CS1503: Argument 1: cannot convert from 'System.Collections.Generic.List<UnityEngine.Vector3>' to 'UnityEngine.Vector3'

sage latch
#

Which one is generally preferred?

readonly Stack<OverlayData> _overlays = new();

public struct OverlayData {
    public string Header;
    public string Subtitle;
    public Overlay Instance;
}
readonly Stack<(string Header, string Subtitle, Overlay Instance)> _overlays = new();
```This feels like a small thing but that people have *very* strong opinions about
sage latch
#

Or do you want to add all the instances of this class to the list at the bottom?

agile tulip
#

Yep I think so indeed

#

I was fiddling with it like this

public class TargetClass
    {
        public GameObject targetGameObject;

        public TargetClass(GameObject _targetGameObject, )
        {
            targetGameObject = _targetGameObject;
            // here a list for waiting
            List<GameObject> waitingQue = new List<GameObject>();
        }
    }
    public static List<TargetClass> targetList = new List<TargetClass>();
sage latch
#

The "correct" way to do this is actually

public class TargetClass
    {
        public GameObject targetGameObject;
        public List<...> list;

        public TargetClass(GameObject _aiGameObject, IEnumerable<...> _list)
        {
            targetGameObject = _targetGameObject;
            list = _list as List<...> ?? _list.ToList();
        }
    }
```Because the `IEnumerable` class allows for more flexibility, for example being able to pass an array instead of a list
agile tulip
#

The new List<GameObject>() new list isn't even needed?

sage latch
#

Depends on if you pass the list through the constructor like I showed

#

If you're just going to pass an empty list, you can instead create it like that

public class TargetClass
    {
        public GameObject targetGameObject;
        public List<GameObject> list;

        public TargetClass(GameObject _aiGameObject)
        {
            targetGameObject = _targetGameObject;
            list = new List<GameObject>();
        }
    }
agile tulip
#

Yeah creating a new list, think I need the bottom one

sage latch
#

This one? public static List<TargetClass> targetList = new List<TargetClass>();

agile tulip
#

That's the parent class list

sage latch
#

Oh you meant the bottom code I sent

#

Yeah, that would be the best one if you want a new list

agile tulip
#

targetList[0].targetGameObject

#

targetList[0].waitingQue[0]

#

those I gonna need when the list is finished

#

after I put objects in it ofcourse XD

sage latch
#

Should work 👍

agile tulip
#

Thanks for the help buddy!

sage latch
#

Just remember to actually add the instances to the parent class list

agile tulip
#

Oooh wait then I need the other example right?

#
public class TargetClass
    {
        public GameObject targetGameObject;
        public List<GameObject> waitingQue = new List<GameObject>();

        public TargetClass(GameObject _targetGameObject, List<GameObject> _waitingQue)
        {
            targetGameObject = _targetGameObject;
            // here a list for waiting
            waitingQue = _waitingQue;
        }
    }
    public static List<TargetClass> targetList = new List<TargetClass>();
#

wauw I'm confused XD (smoke brb)

#

Yeah I think the example above should work

agile tulip
urban marsh
#

Hello everyone !
I have a question : Which is these two lines of codes is usually better ?

// OR
transform.RotateAround(casterTransform.position, Vector3.forward, angleSpeed * Time.fixedDeltaTime);```
cosmic rain
urban marsh
#

Maybe split it into several lines though
How so ?

agile tulip
bright relic
#
                if (heightEast != heightValue)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        vertices[v] = new Vector3(vertexOffset, heightValue + i * ((heightEast - heightValue) / 3), -vertexOffset) + cellOffset + gridOffset;
                        vertices[v + 1] = new Vector3(vertexOffset, heightValue + i * ((heightEast - heightValue) / 3), vertexOffset) + cellOffset + gridOffset;
                        vertices[v + 2] = new Vector3(vertexOffset, heightValue + (i + 1) * ((heightEast - heightValue) / 3), -vertexOffset) + cellOffset + gridOffset;
                        vertices[v + 3] = new Vector3(vertexOffset, heightValue + (i + 1) * ((heightEast - heightValue) / 3), vertexOffset) + cellOffset + gridOffset; ```
how can i adjust this code so the top and bottom face are smaller and the middle one gets stretched between them?
cosmic rain
indigo haven
#

Hi, good day.
I have a little problem with coroutines.
I have a method that start a coroutine that starts some on its own.
If a button is pressed i want to stop all those coroutines to start again.
How could i do that? As far as i know i could do it by name but, is there any recursive way to destroy all the coroutines that were called by one method?

heady iris
#

this nukes every coroutine that a behaviour has

#

alternatively, make a List<Coroutine> and put the coroutines you want to cancel in it

#

then just iterate over it and stop all of them

indigo haven
#

I think i can nuke them.
All the coroutines are started from a manager object and i want to destroy them in that object so this could work. I will try, thanks

heady iris
#

Coroutines are always running on a specific behaviour

#

so you'll need to stop them on whichever behaviour you called StartCoroutine on

indigo haven
#

Just to make sure i understand that. If i called them from a gameobject script i can only stop them from inside that gameobject (not necessarily the same script)?

swift falcon
#

surely this is not performant?

heady iris
#

doesn't seem horrendous

#

I would make it so that it only runs when you actually need to toggle the UI

indigo haven
#

Is there anyway of provoking the OnValueChanged of a dropdown menu when selecting the same option again?

quaint rock
# swift falcon

would not worry about it, but if you are worried just have build the list of gameobjects once and loop it later

#

though would be better off just setting up a event that triggers when armourPanel.activeSelf changes

swift falcon
#

might be fine though

keen solstice
#

should i bother with a dedicated UI manager that handles dialog, menu settings and inventory UI, or just have pieces of code that do the same things but less centralized?

#

my game is incredibly light on the UI (only basics like the inventory, settings and some display options)

swift falcon
#

but they both sit on the Main player

quaint rock
bright goblet
#

hi um is it better to use Visual Studio 2022 or Visual Studio Code with Unity?

grave arch
#

Anyone who knows of a good tutorial showing how to fill a tilemap using a rule tile?

fervent furnace
#

i use vs code since it load faster on my pc....

grave arch
# potent sleet did you look online ?

Well yes, I missed a crucial word there though, I want to fill it using perlin noise, but I guess my question would rather be, "is it possible to use a rule tile like a normal tile in that regard when populating a tilemap using code and not the editor and how would that look like?"
Since I how it's nice to just configure the rule tile in one space and the editor just place the type of tile it needs there

static lantern
#

Getting an UnauthorizedAccessException when attempting to write my game data to the disk:

public static void SaveWorldData(WorldData wd)
        {
            if (!Directory.Exists("worlds")) Directory.CreateDirectory("worlds");

            string location = $"worlds/{wd.name}";
            string json = JsonUtility.ToJson(wd);
            StreamWriter sw = new StreamWriter(location);
            sw.Write(json);
        }
primal wind
#

Try File.WriteAllText

static lantern
primal wind
#

Uh

#

I never encountered that issue before so i don't really know how to help

#

Maybe the target path is protected?

static lantern
swift falcon
static lantern
# swift falcon

If those libraries are throwing issues, that's an issue with the library.

#

Not an issue with anything you've done.

sage latch
#

First post the code in a proper way

swift falcon
#

? how

potent sleet
#

!code

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.

sage latch
#

It looks like you need an instance of the WebBrowser class to access all of those methods as they're not static

steep herald
#

Is there any way at all to affect how the properties of a transform component are serialized in the editor?

sage latch
#

its 600 700 lines

primal wind
#

iirc csharp works too

static lantern
#

Jesus fuck guys my goddamn bad.

primal wind
#
public static void Main(string[] args)
{
    Console.WriteLine("Hello World!");
}
#

I can't really see it on mobile

#

so idk if it worked

#

I guess it didn't

static lantern
#

Null, fucking chill dude.

swift falcon
steep herald
#

and possibly directly assign ws coordinates while thats going on

potent sleet
primal wind
#

I've never tried before but, nothing is stopping you from inheriting from a Unity component like Transform right?

swift falcon
#

How to do it ?

potent sleet
#

not the one in the error

formal slate
#

I am in an issue
My game has a level system and has levels stored in containers, the containers store all the data about the level and are loaded up when selected, the problem is I want my game to have 2 level systems and currently I am doing is if the level on the level screen selected had number 1 then load level number 1 and its getting a little strange as I am not able to understand how can I load the same type of file with the same name but with different data in a differenet level system, I have never made a level system before please tell if I am making any mistakes

#

The method I was using is now even interfering with my level editor that I made for the game

leaden ice
#

what does "different level system" mean?

formal slate
leaden ice
#

I don't really know what that means

#

but how are "classic" and "daily" levels different?

formal slate
#

Like the normal level system unlocks level once you complete the previous one and the daily one will unlock once the next day starts

leaden ice
#

Sounds like the levels are all the same but you're describing different systems for unlocking them. Shouldn't they all be represented in the same way then?

formal slate
#

I am categorising levels in 2 forms, the game is like match 3 game which has levels and once you complete level 1, level 2 unlocks

Whereas I am implementing a different level system where if you finished level 1 then level 2 will unlock the next day and I want to keep both of them

leaden ice
#

Yeah just sounds like you need to separate the concept of a level itself from how that level gets unlocked

formal slate
leaden ice
#

different how

formal slate
#

This chat really isnt going anywhere

cunning meteor
#

for some reason i keep getting this error when using vector3 and quaternion

formal slate
leaden ice
leaden ice
#

you added it by accident

#

and you don't want it

cunning meteor
#

how did you know that your brain is so big you could just see the future

formal slate
# leaden ice well you'd have to explain to us, because we know nothing about your game.

Let me explain from the start

There is a level select screen which opens some set of levels and the levels in that are unlocked like any other game , complete the previous one and the next will unlock.

And there is another level select screen in the same scene that will unlock level 1 on jan 1, 2024 and level 2 on jan 2, 2024 and so on.

The levels will be fifferent in both level selectors as I want users to play special levels on festival days which are specially decorated

My implementation for the level select screen is that if I clicked level 1 then it will look for the data that has int 1 and will load it and now I am confused how can I implement the second level selection screen which unlocks levels on daily basis.
Is there a better implementatuon for level selection?

heady iris
#

well, the error also explicitly explains the problem

jaunty sleet
#

Does anyone know how I can get an event from a static script to trigger something in my non static game manager script? I have a static level editor script that creates a custom window for my game and I would like an event to be triggered in my game manager when I press a button in the level editor

#

I don't think I can give the level editor a reference to my game manager like I normally would because it is static

quaint rock
#

static events that your game manager subs to

jaunty sleet
abstract timber
#

hey there what is the current state of fixedstring

#

cant seem to access the struct but it does exist

#

it says it's in the unity.collections but it does not find it

#
public NetworkVariable<FixedString32> playerName = new NetworkVariable<FixedString32>();
winged mortar
# jaunty sleet How would I do that?

static events would just be

public static Action OnSomething:

// invoke like
onSomething.Invoke();


// Subscribe like

onSomething += () => {Debug.Log("This lambda gets exectued when you invoke onsomething");}
#

Unless you are talking about editor scripts

jaunty sleet
#

it is an editor script

winged mortar
#

Is the editor script attached to a gameobject?

jaunty sleet
#

no

#

it is static

winged mortar
#

Looks like you can just use Object.FindObjectOfType

hard sparrow
#

Why is this never firing??

potent sleet
hard sparrow
#

Yes, yes, and nothing should be blocking raycasts either

potent sleet
#

is raycast target enabled on this Image component

hard sparrow
cunning meteor
#

does anyone know how to easily save things

potent sleet
# hard sparrow

try debugging the Event System in Playmode and check what you're actually hovering

hard sparrow
#

The target and the draggable object are on different canvas, thought I put them on the same canvas and it still didn't work

potent sleet
#

it should expand the panel to view your mouse ray

hard sparrow
#

also here is draggableobject

#

Ah, needed to disable raycast target on all the subcomponents of my draggableobject

potent sleet
#

👍

shrewd meteor
#

I am receiving this error and not sure why, the code looks fine and I've made sure that the navmesh is baked. I thought maybe it was because the script and navmeshagent were on the gameobject that is used to store the guards, but that doesn't seem to be the problem either. What am I doing wrong?

potent sleet
shrewd meteor
heady iris
#

make sure the enemy isn't floating above the navmesh, for example

shrewd meteor
heady iris
#

where is the enemy?

#

also, ensure that the error is coming from the instance you think it's coming from

#

i think that, if you click on the error message while the game is running, the offending object will be highlighted in the hierarchy

shrewd meteor
potent sleet
shrewd meteor
heady iris
#

single click

shrewd meteor
potent sleet
#

show Guard Controller script

shrewd meteor
potent sleet
dull yarrow
#

I have Item class and have a weapon class that have the item as inherence class
How can i add that weapon as a item in my List<Item> charInventory;

potent sleet
dull yarrow
#

Thanks

shrewd meteor
potent sleet
#

0,0,0 is default world pos, is your navmesh anywhere near that

potent sleet
shrewd meteor
potent sleet
#

so you know where it is before you run SetDestination

shrewd meteor
#

I'll run it rn

languid hound
#

I don't know if I'm just having a massive brainfart or what but I literally just cannot think of a solution. Lets say I wanted something to get more red the closer it was to a value how would I do that?

#

Obviously health starts at 100 but I want it to be more red the closer it is to 0 not 100

shrewd meteor
potent sleet
#

etc

#

ops

languid hound
#

I wanted to change dynamically

#

Which is why I cant figure out a math solution for it lol

potent sleet
languid hound
#

So like lets say an object is about 10 units away from a sphere

hexed pecan
languid hound
#

The closer it gets to that sphere the more red it gets

hexed pecan
#

Yeah gotta use it on the start position too

#

if(NavMesh.SamplePosition(...)) transform.position = hit.point

#

If hes getting the error about the agent not being on the navmesh, that is

potent sleet
#

yeah i would def check _Target too

potent sleet
shrewd meteor
#

but this wouldn't work, wouldn't that make the position of the current guard the hit position?

hexed pecan
#

This is how you make sure that the agent is on the navmesh

#

Then again I didnt read your whole convo so idk if thats even the issue?

shrewd meteor
#

it is 😭

hexed pecan
#

Okay why are you crying?

#

I proposed a solution

dusk apex
shrewd meteor
hexed pecan
shrewd meteor
#

bet

hexed pecan
#

Doesnt hurt to turn up the distance though

#

Which is currently 1.0f

shrewd meteor
#

yeah I'll crank it up to 5

shrewd meteor
quaint crypt
#

hello, i'm trying to capture mouse clicks in the scene window from an editor window that i open up from the menu. im adding the following code to both the OnGUI() methods, as well as OnSceneGUI(), but it only captures clicks on the editor window itself, and not in the scene view. any ideas why?

Event e = Event.current; if (e != null & e.type == EventType.MouseDown && e.button == 0) { Debug.Log("sup2"); }

shrewd meteor
#

even if I turn it up to 20 it still says it's too far away wtf??

hexed pecan
#

Something else is not right. Agent settings, maybe multiple nav meshes idk

#

Draw a debug line from transform.position to the new position?

#

Debug.DrawLine(transform.position, hit.point, Color.magenta, 10f); inside the if statement

#

Did you also make sure that there are no extra objects with this script?

shrewd meteor
shrewd meteor
hexed pecan
#

Where did you put the debug line, and is that code even running? Make sure it is

shrewd meteor
hexed pecan
quaint crypt
shrewd meteor
#

i dunno why the capsule goes through the floor either

quaint crypt
hexed pecan
#

You can put the capsule on a child and move the child up

potent sleet
#

instead of transform.position =

hexed pecan
#

Maybe

potent sleet
#

tbh that capsule gizmos is not even showing the navmesh agent component cilinder

potent sleet
hexed pecan
#

I think you have to make that true so that changes to transform.position will affect it?

potent sleet
#

yea just notices 😅

hexed pecan
#

Not sure tbh, I dont work with agents, just navmesh

potent sleet
potent sleet
#

not sure if you tried it

potent sleet
shrewd meteor
potent sleet
#

it returns a bool

#

like SamplePosition

#

but it returns if result was success

shrewd meteor
potent sleet
#

you have to warp the agent to pos not the transform in this case

shrewd meteor
potent sleet
#

did you read the page i sent you at all ?

shrewd meteor
#

I didn't even realise lmoa, sorry

#

so like this?

potent sleet
# shrewd meteor

it's a boolean, use it to see if that will work. if it doesn't then trnsform.position is wrong spot

potent sleet
# shrewd meteor
if(_Agent.Warp(hit.position){
//
Debug.Log("Warped");
}
else{
Debug.Log($"Cannot teleport {name} to {hit.position} -  Distance from agent is {hit.distance}.");
}
sour zealot
#

How can I grab a scriptable object's data from another script

#

like a level select, where it gets all the maps with their scriptable objects

delicate olive
sour zealot
#
using UnityEngine;

[CreateAssetMenu(fileName = "NewLevel", menuName = "Level")]
public class Level : ScriptableObject
{
    /*
     * This class represents a level in a game. It contains information about the level such as the thumbnail image,
     * the level name, the level description, and any other relevant information.
     */

    // The thumbnail image for the level
    public Sprite thumbnailImage;

    // The name of the level
    public string levelName;

    // The description of the level
    public string levelDescription;

    // Any other relevant information about the level
    public string otherInfo;
}
shrewd meteor
simple sable
#

Hey guys. Anyone familiar with the A* Pathfinding Project by Aron Granberg?
I'm using it to follow an object around in my scene but I would like to make its speed constant, which by default is not. Not sure what I need to do to fix that though.

somber nacelle
delicate olive
potent sleet
somber nacelle
potent sleet
delicate olive
delicate olive
#

Wait did you just create that in like 1 minute

potent sleet
#

No I legit screenshot this when someone posted this code

delicate olive
#

Ohh lmao

#

They must've never heard of containers then lmao

somber nacelle
#

you'd be surprised at just how common that is in this discord

delicate olive
#

Yeah I bet

simple sable
sour zealot
#

box

#

can I dm u

somber nacelle
#

no

sour zealot
#

okay

#

help please: ```cs
using UnityEngine;
using TM_Pro;
using UnityEngine.UI;

public class LobbyMenuManager : Monobehaviour
{
[SerializeField] private Level[] levelList;

void Update()
{

}

void DisplayLevels(Level[] level)
{
foreach(level i in Level[])
{

}

}
}

simple egret
#

Syntax error, question expected

potent sleet
#

lol

sour zealot
#

oh yeah

#

Im trying to me a level select ui

#

and I have scriptable objects for each level

#

and I want to display the thumbnail and gamemode

potent sleet
simple egret
#

Mhm, there's still no question here

potent sleet
#

like hella wrong

sour zealot
#

my question is how do I accomplish this

simple egret
#

But yeah you have some invalid syntax

sour zealot
#

i know its wrong

#

its psudo

potent sleet
#

use a for loop and you can match thumbnails list to the levels list

sour zealot
#

yeah

potent sleet
#

use the same i variable

sour zealot
#

ut how do I do it

#

can someone right me an example?

potent sleet
#

make a list of thumbnails gameobjects , make a prefab of 1

#

then spawn them dynamically depending on the amount of levels array

sour zealot
#

yeah

potent sleet
#

put them inside layoutgroup

#

so they stack

sour zealot
#

and then change the color, thumbnail, title, gamemode, and description

simple egret
#

Yeah you need to loop over your array, and for each level, create a new UI object prefab, set the title, the thumbnail. Might want to use UI wrap layouts to have auto-layout

sour zealot
#

can soemeon gimme an example/

#

im a visual learner

simple egret
#

There's 3 tasks here at least

potent sleet
#

start by making the prefab for the display of UI

sour zealot
#

im in school

#

so no

#

just coding rn

potent sleet
#

so come back later

sour zealot
#

but I can get the code done now

#

: O

potent sleet
#

ok so start by creating the UI object class

simple egret
#

First, prefab. As you're going to reuse the visual it's better to make it once and then Instantiate multiple times. On this prefab you'd have a script that you pass your title and image to it, and it takes care of placing them for you

potent sleet
#

eg:

public class LevelObjectUI : MonoBehaviour

sour zealot
#

i dont know how to do that

#

oh

#

do i not have that

potent sleet
#

no

sour zealot
#

why

potent sleet
#

public class LevelObjectUI : MonoBehaviour
this goes on your eventual Prefab

sour zealot
#

im doing scriptable objects

potent sleet
#

so you can access its method on instantiation

sour zealot
#

not monobehaviours

potent sleet
#

you're not listening

sour zealot
#

oooohhhhhhh

#

i see

#

yup

#

yup

#

i know what you mean

#
using UnityEngine;
using TM_Pro;
using UnityEngine.UI;

public class LevelObjectUI : Monobehaviour
{
  
}

#

: )

sour zealot
#

what next : )

potent sleet
#
public class LevelObjectUI : MonoBehaviour 
{
public string LevelName;
public TextMeshProUGUI uiText;
public OtherStuff stuff;

public void Init(string levelname,  etcc){
LevelName = levelname;
uiText.text = LevelName;
etc.

}```
sour zealot
#

i dont get it

potent sleet
#
for (int i = 0; i < levels.Length; i++)
            {
                var instanceUI = Instantiate(LevelObjectUIPrefab, panelStackTranform)
                      InstanceUI.Init(levels[i].levelname, etc..)
                    etc..
            }```
sour zealot
#

i dont know what goes in the etc

potent sleet
#

use your imagination

#

i'm not typing all your code

sour zealot
#

-_-

potent sleet
#

i'm just giving you example

sour zealot
#

ik

potent sleet
#

the logic of what to do should be obvious