#archived-code-general

1 messages · Page 365 of 1

mighty void
#

in the forum i read a lot of replies that tell dont works

#

and try with IPointerEnterHandler but the same

#

are for UI elements

little meadow
#

IPointer guys most definitely work with physics if you add a physics raycaster component somewhere

mighty void
#

but with 2d elements dont really works

#

i have a lot of videos of 3d and i see definitly works

little meadow
#

There's a 2d variation of the component I'm pretty sure

mighty void
#

but y try with a blank scene dont works

mighty void
#

dont works

#

never works xd

little meadow
#

Of course it does

mighty void
#

but works perfectly fine with UI elements

little meadow
#

I've used all of these at some point

mighty void
#

not with colliders

#

i'm using unity 6 dont works XD

little meadow
#

Yes with colliders

mighty void
#

i try everything

#

and nothing happens

little meadow
#

Ah.. well not sure in 6, but unlikely they broke it

#

Perhaps something else was blocking it?

mighty void
#

btw

mighty void
#

i dont know why dont works

little meadow
#

Check the inspector on the event system, see what it sees

#

What it "hits"

mighty void
#

my events system in here

#

i try with trigger

#

matrix layer

#

layers

#

raycast padding

#

nothing works

#

normal collider

little meadow
#

The classes are pretty basic. It's unlikely that they don't work. It's some config issue.

mighty void
#

in this point i'm gonna make my own events

#

with a raycast on the mouse

little meadow
#

That's gonna work a lot less

knotty sun
mighty void
knotty sun
#

OK, and show the inspector of the object you are trying to detect

little meadow
#

1 max intersection could be a problem

mighty void
mighty void
little meadow
#

Keep higher while figuring out

mighty void
#

with 0 or 10 or 2000 nothign happens

#

look

knotty sun
# mighty void

those look fine so it may be your code, post it to a paste site

mighty void
#

i make it with UI elements and works perfectly fine with 2D objects dont works

#

it a debug

rigid island
# mighty void

did you put the EventSystem and did you put the proper Physics Raycaster 2D on the camera

mighty void
mighty void
knotty sun
rigid island
#

I wonder if new input system messes with that. gonna double check rq

mighty void
knotty sun
#

I want to see the full code

mighty void
mighty void
rigid island
little meadow
mighty void
#

your input system are not the same

#

my new event system only works with UI elements

somber nacelle
#

if your camera has a PhysicsRaycaster or PhysicsRaycaster2D (depending on the physics system you are using) then it will work with world space objects too

little meadow
#

that's what we said, but apparently not

somber nacelle
#

i can assure you that it does. the objects being detected will obviously need a collider and of course be on a layer included in the raycaster's layer mask but it does work

little meadow
#

also what we said 😄

mighty void
#

BOXcollider 2d

#

my camera have a physic raycaster 2d

#

i have all :I

#

but i have nothing XD

somber nacelle
#

show the full code

little meadow
#

the event system doesn't seem to be detecting it (or so it seems in the last screenshot I asked for)

mighty void
little meadow
#

might be some issue with the position not being correctly setup in the input system?

mighty void
mighty void
little meadow
#

mine is sucky though

#

I'm in a VR project

#

yours should have more data... at least it used to have more data last time I needed it... am too lazy to set things up now to test though, sorry

#

good luck with it 🤞

somber nacelle
mighty void
#

yeah

#

UI objects are detected

#

in unity api says OnPointerEnter are for UI elements

rigid island
#

yeah but as I mentioned the PhysicsRaycaster makes it work for Colliders
You just need to still have EventSystem ofc

mighty void
#

the same result

rigid island
#

the GIF i sent u earlier thats a sprite with circle collider

mighty void
#

nothing happens

mighty void
#

but its a strange thing i dont know XD

#

i dont know how to fix it

#

i assume is a method for UI elements

#

i make a empty scene an try with a basic script

#

the same result

rigid island
#

it usually is yes.. something else is wrong

#

I will try it on 6 rq but I doubt thats the issue

somber nacelle
rigid island
mighty void
#

uh i have no idea

rigid island
#

did you test the UI objects ?

somber nacelle
#

here's a stupid question, but have you actually clicked into the game view window

rigid island
#

^yea did this before . Double check you actually focused in the gameview by clicking on it after pressing play

willow magnet
#

I'm pretty much at my wits end, I'm using unity6 and I noticed that I'm not launching scripts according to the hierarchy, but it looks like their sequential launch depends on when I added it to the scene (the so-called script that I add last is launched first).
Has anyone encountered this before? I'm pretty desperate

somber nacelle
#

there is no guaranteed execution order for your components. they have never been guaranteed to execute in order based on hierarchy

#

if you are relying on that assumed behavior then you have a serious design problem

rigid island
willow magnet
rigid island
#

pretty simple, use a combination of Synchronous code to initilize them, and events, you should be ok.

stable osprey
rigid island
willow magnet
somber nacelle
willow magnet
#

I dont have initialized reference

rigid island
stable osprey
#

I say for sure but I really mean “iirc”

steady moat
rigid island
#

yeah I would never rely on the hierarchy no matter what

#

disaster waiting to happen

#

i dont even change the Script execution order
if you do that, you have flawed design most of the time (unless its some type of boostrapper script IG)

stable osprey
#

I’ve based a lot of my singletons on this lol.. it’s pretty handy.
if (…) DestroyImmediate(this.gameObject); and no child’s code is executed

willow magnet
#

Well, I don't know, but the problem arises when OnEnable is called on COntroller before awake on PlayerManager, which is a total fuckup, we've never had a problem with this.

rigid island
somber nacelle
#

there is no guarantee that one object's OnEnable has been called after another object's Awake unless that first object was instantiated after that first object's Awake message had already been called

#

https://docs.unity3d.com/Manual/ExecutionOrder.html

Awake is only guaranteed to be called before OnEnable in the scope of each individual object. Across multiple objects the order is not deterministic and you can’t rely on one object’s Awake being called before another object’s OnEnable. Any work that depends on Awake having been called for all objects in the scene should be done in Start.

rigid island
#

me trying to subscribe my Singletons events from OnEnable 😢

willow magnet
#

InstanceID -50312? 😮

somber nacelle
#

none of that matters

#

the order that objects receive their Awake and OnEnable messages is not deterministic. You cannot rely on one object receiving its Awake message before another object receives its OnEnable message

steady moat
#

Negative number means it has been instantiate as far as I know.

rigid island
#

i think bigger negative meaning it was added last

#

if you save n reload the scene they will be positive

steady moat
#

Seem like it is not necessary runtime instanced.

The instance ID of an object acts like a handle to the in-memory instance. It is always unique, and never has the value 0. Objects loaded from file will be assigned a positive Instance ID. Newly created objects will have a negative Instance ID, and retain that negative value even if the object is later saved to file. Therefore the sign of the InstanceID value is not a safe indicator for whether or not the object is persistent.
rigid island
#

ah yes that confirms what I said
if you save n reload the scene they will be positive

#

so yeah instanceID def not reliable to depend on at all, I thought they were relevant to execution timing but seems not

steady moat
#

I guess in a build a negative number is pretty much an instanciated object.

rigid island
#

checking if the instance ID is less

rigid island
# mighty void

add a canvas and a button, see if its working (is the button hovered)

mighty void
#

with ui works

#

the log are for UI element, grass

rigid island
#

well shite

somber nacelle
#

there is something incorrect in your setup then because IPointer interfaces absolutely work with world space objects provided that they have a collider and the camera has the relevant raycaster attached

mighty void
somber nacelle
#

you've got a 3d raycaster on there

rigid island
#

fuuuuuuck

#

how did we not see that

mighty void
#

i know

rigid island
#

oh this is the new scene

#

why did u put the 3d one

mighty void
#

i try with a 2d raycaster

#

and 3d caster

mighty void
willow magnet
rigid island
rigid island
#

use an actual script to control the setup

steady moat
rigid island
#

I prefer to use Events when you need another object to know another object is ready with data

little meadow
#

You can use the DefaultExecutionOrder attribute and force execution order of some things

rigid island
#

putting duct tape on a raft full of holes

willow magnet
mighty void
#

i really dont know how to fix it xd

rigid island
steady moat
#

You should not depend on Enable being called after awake on other object.

mighty void
rigid island
#

@willow magnet scripts runs lines from Top to Bottom. Create a Setup function or Init, control your own flow

rigid island
willow magnet
somber nacelle
#

I don't understand why when awake should always be performed absolutely everywhere and then jump to OnEnable
we've told you why this is several times now

mighty void
rigid island
mighty void
#

its a blank scene xd

rigid island
#

but same project

#

just try it

mighty void
#

i'm going to try

rigid island
#

could be some player settings touched, maybe overlooked
You wont know for sure until you narrow down

willow magnet
somber nacelle
#

this is how it has always worked. and the documentation that you have been provided very clearly states that there is no guarantee that one object's Awake method will be called before another object's OnEnable method. that is the whole fucking point. and your entire issue.

willow magnet
#

I've never come across this kind of behavior... But after realloading the scene, it's suddenly called exactly as I need (interesting, isn't it?) and it's also interesting that a non-negative InstanceID was assigned.
Even wake on Playermanager is called before WeaponController, before realload WeaponController was literally called first.

somber nacelle
#

alright you're clearly not listening so i'm done engaging with this

rigid island
#

the instanceID will have no relevance to your scripts order now, and how you should set it up. If you did before, it was by chance that it worked out until it didnt.. Never rely on what you cannot control

willow magnet
# rigid island the instanceID will have no relevance to your scripts order now, and how you sho...

But I'm not claiming anywhere that it's relevant and that it's worn out because of it, it's just that it's interesting that as soon as I'm given a non-negative number after reloading the scene (which is even higher than the manager's), it's called correctly. Unity6 is not stable, so I don't understand why it couldn't contain errors, even in something like this.
So far it hasn't happened to me even once, it could be some unity state, property, anything that went wrong.

rigid island
#

its not broken, its by design

willow magnet
rigid island
willow magnet
#

No, it wasn't, I didn't notice problems with previous versions, certainly not in functionality with monobehaviour

eager fulcrum
#

Hey I have some issues with dragging objects.

#

basically all of these are the same prefabs

#

and I can drag items across slots on the bottom

#

but I can't drag them to the slots on the top ui

velvet zealot
#

none of this code is working for somereason i have ran Debug.Log("") to make sure void Start is running and it is so im not sure why it isnt affecting my game

eager fulcrum
rigid island
rigid island
eager fulcrum
#

shoot a ray at OnEndDrag?

rigid island
#

EventSystem can be inspected in Play mode you should be able to see what ur mouse is hovering. Or its probably something between the two images, in that case maybe print OnDrop

eager fulcrum
#

hmm thats weird

#

it logged that the correct thing was under the mouse

#

but it didnt enter OnDrop

rigid island
#

also would double check this value ? transform.childCount != 0

#

or didnt run at all

#

isnt OnDrop the item that got dropped on?

eager fulcrum
#

actually there was something blocking the ray

mighty void
oblique basalt
#
public class PlayerBrain : MonoBehaviour
{
...
    void Attack(){
        if(attackInput.action.IsPressed()){
            if(TryGetComponent(out CharacterAttack characterAttack)){
                characterAttack.Attack();
            }
        }
    }
...
}

public class CharacterAttack : MonoBehaviour
{
    ...
    void Attack(){
        if(equippedWeapon.hasSwingAnimation){
            weaponAnimator.SetTrigger("Attack");
        }
    }
    ...
}

I've got this simple setup for triggering animations, but it triggers the Attack animation twice. I've read online that its because I'm checking action.IsPressed() instead of checking action.started. However I want the player to be able to hold the attack button to continuously attack. I'm not completely sure how I should deal with this.

mighty void
rigid island
mighty void
#

new empty proyect

#

2d proyect

rigid island
#

weird..

mighty void
#

inputactionasset have anything?

rigid island
# mighty void 2d proyect

I can send you a blank project where the setup is working, but unity 6000.4
then you can double check if its the editor or something

mighty void
#

maybe disble some thing or enable?

#

send it

rigid island
#

ok one sec ill put it on github

rigid island
mighty void
#

in both proyects i use both

#

old and new input system

rigid island
#

you set Player settings on both right ?

mighty void
#

yeah

rigid island
#

its going to ask you in hub the missing unity version just upgrade it to your version and hit Continue when it asks prompt. It might take a bit to rebuild project

timid briar
#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TriggerAnimation : MonoBehaviour
{
[Serializefield] private Animator ZombieIdleNew;

[Serializefield] private string zombieIdle = "atack1"

private void OnTriggerEnter(Collider other)
{
    if (other.CompareTag("Player"))
    {
        ZombieIdleNew.play(atack1, 0, 0.0f);
    }
}

}

#

Not working

fair jackal
#

Define “not working”

#

Also you might wanna slap in debug statements at different sections to see what’s running and what’s not

timid briar
tawny elkBOT
rigid island
#

"not working"

#

well no shit

#

you got tons of errors

#

also why Unity 2018 ?

oblique basalt
#
public class PlayerBrain : MonoBehaviour
{
...
    void Attack(){
        if(attackInput.action.IsPressed()){
            if(TryGetComponent(out CharacterAttack characterAttack)){
                characterAttack.Attack();
            }
        }
    }
...
}

public class CharacterAttack : MonoBehaviour
{
    ...
    void Attack(){
        if(equippedWeapon.hasSwingAnimation){
            weaponAnimator.SetTrigger("Attack");
        }
    }
    ...
}

I've got this simple setup for triggering animations, but it triggers the Attack animation twice. I've read online that its because I'm checking action.IsPressed() instead of checking action.started and that this causes the triggers to stack? Seems pretty weird that the trigger doesn't automatically reset itself but im sure theres a reason. Anyways II want the player to be able to hold the attack button to continuously attack. I'm not completely sure how I should deal with this.

rigid island
#

or performed .. iirc I havent touched events on new input yet

oblique basalt
#

ahh ill take a look

rigid island
#

can you show the transitions, maybe the clip is there twice

oblique basalt
#

how could it call the function more than once anyways when its in update?

rigid island
oblique basalt
oblique basalt
rigid island
oblique basalt
#

jesus yeah im not sure why im not just using a bool that is equal to whether the key is pressed mb

#

should work fine after that

#

thanks

rigid island
#

sure, hopefully that does it

oblique basalt
#

👍

vital granite
#

Need help understanding what I screwed up here
I keep getting the error "MissingReferenceException: The object of type 'CanvasGroup' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object." after leaving the scene for another and then reentering the scene
The error pop ups here and I don't know why
https://gdl.space/oqomoqakes.cs

rigid island
vital granite
rigid island
#

can you show the hierarchy

vital granite
#

Sure give me a sec

#

The objects with canvas groups are Pause Screen, Pause Screen Base, and Y/N Layer

leaden ice
#

Are you using any DDOL objects/scripts?

vital granite
#

DDOL?

leaden ice
#

DontDestroyOnLoad

#

You are also using static variables I noticed

#

which are very likely to cause this kind of error

vital granite
leaden ice
#

I'm guessing from a static reference or something

#

Show your full stack trace of the error

#

it will give us more clues

rigid island
#

also you should link all these in the inspecor btw, no reason to use Find by name if they are all part of the scene together

   private CanvasGroup pScreenBase;
    private CanvasGroup ynScreen;
    private GameObject ynInitial;
    private GameObject pScreenPrev;
    private TMPro.TMP_Text ynText;```
leaden ice
#

Better yet, reference the CanvasGroups directly

#

There is rarely a good reason to have a GameObject variable unless you plan to call SetActive on it only

vital granite
leaden ice
#

show that code

#

My guess is you're failing to unsubscribe an input listener that you subscribed

#

that's a pretty common mistake

leaden ice
#

right so you're doing this:

        player.Pause.performed += ctx => pause.Pause();
        menu.Pause.performed += ctx => pause.Pause();```
#

but you never unsubscribe

#

and since you also never disable menu...

#

it's still being called

#

You're only enabling and disabling the Player map:

    private void OnEnable()
    {
        player.Enable();
    }
    private void OnDisable()
    {
        player.Disable();
    }```
#

Why not just do this:

    private void OnEnable()
    {
        playerInput.Enable();
    }
    private void OnDisable()
    {
        playerInput.Disable();
    }```
#

enable and disable the whole thing

#

You really shouldn't use static variables for this stuff though... it's a disaster

vital granite
carmine osprey
#

what would be the best way to detect if my wheelcollider car is accelerating or deaccelerating to play the right engine audio?

leaden ice
#

So it depends on your code.

carmine osprey
leaden ice
#

Engine audio is based on how hard the engine is pushing

#

Aka, your input

void basalt
#

if you want a realistic sounding car, you'll need a basic transmission and "gear" setup

#

you can fake most of that

#

engines have a torque curve, and they'll output different amounts of torque at different RPM. <-- this might be completely useless information for unity's wheel colliders because they're pretty wack

carmine osprey
#

i figured it out. thank you

hexed whale
#

What are Physics2D.FIndNewContacts and Physics2D.SolveDiscreteTraversal and why are they taking so much cpu? With 2500 enemies these 2 take up 56%, according to non-deep profiler!
Some information about the environment - 2d sidescoller, this enemy can only(!) collide with ground and walls and I don't think there are any enabled colliders aside from walls, grounds and these enemies(which should not collide with each other at all). What in the world creates these discrete islands in such quantities(I've seen 25k at least once)? Should I forget about the convenience of dynamic rb 2d and switch to kinematic or something else entirely?

rigid island
cosmic rain
rigid island
#

2500 sounds like a lot of colliders / physics to calculate

#

box2d prob cant cope

night harness
#

Is there any easy way to compare generic values when im messing with these kinds of values, structs and objects? or should i just have some sort of abstract function that they need to implement

    [System.Serializable]
    public class BoolSetting : ValueSetting<bool> { }

    [System.Serializable]
    public class FloatSetting : ValueSetting<float> { }

    [System.Serializable]
    public class IntSetting : ValueSetting<int> { }

    [System.Serializable]
    public class StringSetting : ValueSetting<string> { }

    [System.Serializable]
    public class Vector2Setting : ValueSetting<Vector2> { }

    [System.Serializable]
    public class Vector3Setting : ValueSetting<Vector3> { }

    [System.Serializable]
    public class ColorSetting : ValueSetting<Color> { }

    [System.Serializable]
    public class ObjectSetting<M> : ValueSetting<Object> where M : Object
#

glancing online at some of the c# interfaces but they dont seem to cover all my usecases in a simple way

hexed whale
rigid island
#

do you have very complex shapes? (like polygon collider ? )

hexed whale
#

on each of them, but still.

rigid island
#

it still sounds like a lot of dynamics rb at once, but I havent profiled Box2d engine too much

#

do they all need to be active at once?

#

its generally cheaper to keep them as simulated = false until you actually need them

rigid island
hexed whale
rigid island
rigid island
hexed whale
#

What I mean is, I cannot just block their movement.

#

Or disable them

rigid island
#

not block but do they all need physics simulations ?

#

they can be moved with transforms while not seen , depending on the game pfc

#

also are there any enemies clumping colliders together when inside/outside of screen ?

hexed whale
#

Actually, the whole idea for the dynamic rb2d was to implement a simple leap XD The whole point of this box collider is to not fall into the ground. Target raycasting is done using appropriate hashsets anyway(+ Bounds).

rigid island
#

the collider isnt issue as much all those dynamic rbs calculating so many collisions / changes in contacts

hexed whale
rigid island
hexed whale
rigid island
# hexed whale

btw what did Physics 2D section of profiler say, esp for total contacts

hexed whale
hexed whale
rigid island
#

oh i missed the second screenshot mb lol

#

i even screenshotted it xD

#

yeah that is wild amount of processing

hexed whale
#

Yeah, might as well forget about convenience and remove rb 2d from all enemies ^(

rigid island
#

just apply it when you need it

#

19mb is pretty crazy lol

hexed whale
#

Yes XD

somber nacelle
#

2500 dynamic rigidbodies is quite a lot, and if you are keeping them awake and simulated then they all must update every fixed update

hexed whale
#

Hmm. But what if I toggle simulation only for leap ability? and remove the box collider 2d. Just, anything else aside from leap can be handled by rb set position..? But that would mean Raycasting, one for wall facing and one for ground... need to compare and see what is more performant actually! Might actually be a better way.

rigid island
#

btw it aint the box collider issue, its the dynamic rigidbody causing issue

#

if anything put rb.simulated = false when not in use

hexed whale
#

Yeah, the collider is just not needed anymore because everything will be raycast-based

#

Really interesting to see the performance difference XD

rigid island
#

raycast fairly cheap

rigid island
#

or detecting other moving

hexed whale
rigid island
somber nacelle
#

raycasts are very cheap. I tested 1000 raycasts using Physics2D.Raycast and it averages 0.32ms for all 1000. of course that was in a completely empty scene so i'm sure having colliders and other bodies in the scene will probably impact that, but it is still very cheap

hexed whale
plucky aurora
#

has anyone tried unity muse for coding?

#

is it better helper than chat gpt or alike?

#

if its made by unity perhaps it knows about most things unity related unity muse i mean

rigid island
#

half the things it said were incorrect and most of the docs links were broken, who knows if its fixed..
not worth the monthly cost

#

gpt performed better in most cases

hexed whale
#

I start to think I can try to code leap with no rb 2ds XD

#

physics is dull

#

No point in having a lag spike on leap state on spawn enemies

rigid island
hexed whale
#

my last hope in rbs are kinematic ones, and then I switch to pure transforms XD

somber nacelle
#

if the point of the rb is to respect collisions, then making it kinematic won't help. kinematic bodies are not affected by outside forces, including collisions

hexed whale
#

no, kinematic for enemy to be a proper raycast target. All movement including leap is on my side(hopefully)

somber nacelle
#

it doesn't need a rigidbody at all to be detected by a raycast

hexed whale
#

and these enemies move

somber nacelle
#

if you implement your own collision checks it won't be a problem. the issue mainly stems from the fact that moving the colliders doesn't respect physics

hexed whale
#

no, not that. I've heard somewhere that it is an advice from Unity to move colliders best with rb attached because otherwise you get a recreation of this collider every frame because it's internally bound to a hidden static rb in a scene... Memory falls short where or when, but "the issue mainly stems" is not exactly correct afaik.

somber nacelle
#

you've "heard somewhere" so provide a source

hexed whale
#

sure, but time will be needed.

#

not much though

somber nacelle
#

and was a 3d issue only

#

either way though, your performance concerns are going to be more about how you get 2500 moving objects to not run like ass without using DOTS

hexed whale
#

my target is webgl 🙂

somber nacelle
#

not with 2500 dynamic objects it isn't 😉

hexed whale
rigid island
tired elk
#

Hi ! Question concerning AssetBundle: if I use LoadAllAssets(someType) to load a portion of the content, then later use LoadAllAssets() to load the remaining content, are previously loaded assets loaded again ? Can't find information about that kind of filtering mechanism in the documentation.

open plover
#

you could test it

prisma skiff
#

Is it possible to change soft shadow quality in URP programmatically? Everything I find is changing the shadow resolution - I want to change the quality in this dropdown with code if possible:

leaden ice
prisma skiff
#

Hmm that sucks - not ideal. I guess I'll just give the player the option to set soft shadows on or off, without being able to change the quality. For those curious in case you're searching Discord:
URPAsset.supportsSoftShadows = bool;

fast glade
#

(im not really sure where to post this kind of problem so ill just post it here)
so im currently using unity's navmesh system, and I pretty much want to make a moving obstacle walkable and non walkable at certain times during runtime, problem is it wont even be walkable when i start the game, i already used stuff like navmesh modifiers but it just wont work

fast glade
mossy oyster
grand skiff
#

Hi folks, I hope you are doing well, I am new to this server, I need some information about Nethereum and Unity. I want to do transactions through Unity and want to use metamask wallet I need the code of Unity C#, can anyone guide me?

dawn nebula
#

I have a vector. I want a quaternion rotation that is aligned with this vector. Any good helper methods for this?

spare dome
#

if im being honest

lean sail
dawn nebula
golden sinew
#

guys i made a script that spawns squares in a limited range (2d), but how can i prevent them overlapping?

i tried but where did i do wrong?

#

in this code, squares immediately gets destroyed and spawn new ones

#

i tried to decrease/increase the radius of overlapcircle

#

still nothing

spare dome
leaden ice
golden sinew
#

but like i said, for some reason overlapcircle works weird

#

ohhh wait i should have said this in first place

#

this is a 3d isometric game normally

#

but i made a new scene just for this

#

i even tried overlapsphere (adding them 3d box collider)

golden sinew
#

it didn't worked

drowsy crest
#

Guys, my line button.onClick.AddListener(ButtonClicked); will call the "ButtonClicked" function twice in a row when it's clicked, yet if I remove that line, the ButtonClicked function is not called at all. So if I was doubly binding it or calling it elsewhere, I'd see one call when I remove the line, not none. In fact I searched the entire solution for "ButtonClicked" just to make sure it's not being referenced elsewhere and it isn't.

Why is it getting called twice for one click?

#

Callstack shows it's coming from UnityEngine.UI both times

#

That may as well be 2 identical screenshots. But I'm getting 2 Debug.Log outputs from within ButtonClicked, and only one output from another event listener function on the same button.

#

For the same, single click

lean sail
left python
#

!code

tawny elkBOT
drowsy crest
#

Actually

#

maybe the line that adds it is being called twice, I didn't check that, hang on...

lean sail
left python
#

Code: https://gdl.space/ojifojubov.cs
I have an issue with a collider, when Instantiate an object and place it where my raycast hits I am getting collision issues with objects that are not square. I have a box collider on a prefab and on the long side the collision works fine, but when I rotate the object doesnt seem to collide from the small side, its almost like my box collider isnt rotating. I can get a video if needs be

drowsy crest
#

Related question - is there a way to print out how many event listeners onClick has registered to it?

#

(The Debug.Log statement int he previous screenshot is being called twice, it exists inside ButtonClicked)

left python
#

@drowsy crest Any idea on my issue 🙏 ?

rigid island
drowsy crest
lean sail
left python
left python
#

But if i use a box it works fine

rigid island
#

also take a screenshot when you turn it with the Physics Debugger , under Queries tab

left python
#

I have in the past, let me re add a gizmos in

left python
rigid island
left python
#

Ooooh that shows me a lot actually, let me get a screenshot

#

This is when its correct-

#

When its rotated 90deg -

#

And then a 45 degree angle -

#

So something must be wrong im just not sure what or how to fix it

rigid island
#

seems the cast isnt rotating properly

left python
#

Thats a really cool menu, any idea how to fix it?

rigid island
#

oh you're using the bounds not the collider

#

esp when you rotate it angled, it fills the whole cube. Since bounds are that

left python
#

Am i not using the collider bounds?

#

How would you go about doing it, or do you have a link youd recommend i look at

rigid island
#

Collider[] colliders = Physics.OverlapBox(bounds.center, itemCollider.size, placementObject.transform.rotation, buildableLayer);

#

its half extents so you need /2 actually I think

left python
#
        Vector3 size = itemCollider.size;
        Vector3 center = itemCollider.center;
        Bounds bounds = new Bounds(placementObject.transform.TransformPoint(center), size);

        Collider[] colliders = Physics.OverlapBox(bounds.center, bounds.extents, placementObject.transform.rotation, buildableLayer);

With a bit of fiddling and a hint of chatgpt i got this to work

leaden ice
spare dome
tawny elkBOT
#

:teacher: Unity Learn ↗

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

left python
spare dome
#

well all chatgpt is, is a program that has access to the internet and pulls from websites and strings them together to get a answer. if your gonna use anything best suggestion is to look said thing up

rocky basalt
#

So is OnCollisionEnter/OnTriggerEnter really that unreliable for complex MeshColliders in motion? I have a collision that works fine for BoxCollider, but MeshCollider doesn't register the event at all. I even set it to convex and tried continuous collision detection. Both objects have RB's (only 1 is kinematic), Colliders, and the physics layers are compatable

After a bunch of troubleshooting, the only answer I saw was Complex meshes can sometimes cause issues with collision detection. If you need precise collisions with a complex shape, consider simplifying the mesh or using a combination of MeshCollider and simpler colliders."

night harness
#

This is less of a problem and more of a curiosity,

I've got this ScriptableObject with some custom classes declared but the instances of them are null when the SO's OnEnable is called when I first make the asset. If their null at that point, when do they get initialized?

    public class ScriptableAudioSetting : ScriptableSetting
    {
        public override List<ValueSetting> GetValues() => new List<ValueSetting> { Volume, DbMinMax, AudioMixer };

        public ObjectSetting<AudioMixer> AudioMixer;
        public FloatSetting Volume;
        public Vector2Setting DbMinMax;
    }
#

wait i might be dumb actually hm

#

it's actually that getvalues thats null

chilly surge
#

One simple solution is to calculate the position like you currently do, then add some small random shift to the result.

#

Another solution would be give a random delay before the bot can act on moving to the desired position, to simulate reaction time.

#

And of course can combine the two, adjust parameters to the shift/delay to make the difficulty adjustable.

leaden ice
#

Make it move more slowly

plain halo
chilly surge
#

Break it down into smaller parts and figure out each one.

faint tree
#

im looking at the memory profiler and seeing graphics in there that arent in the game currently, anyone have an ideas how that happens..

cosmic rain
#

If you need more precise answer, you should share some profiling data that you're looking at.

faint tree
#

thank you very much, yeh im testing on an android build.. the only reference to it is a reference to an addressable that isnt loaded yet, so its difficult to know why its in memory

cosmic rain
#

What kind of a resource is it? A prefab?

faint tree
#

theyre texture2Ds,

#

i can pin point when they turn up, but i cant see how or find any references in the scene, very strange

soft shard
#

Im confused, my spherecast (non alloc) is returning the correct object but a point of zero (and a normal in the opposite direction im casting), looking online suggests its cause the origin starts inside an object, but even moving the origin outside doesnt change anything, also the cast ignores the layer of the object is "inside" and that object doesnt have a collider, so this shouldnt matter anyway - using hit.collider.ClosestPoint(transform.position) gives me exactly what I want hit.point to give me, it IS hitting the correct object, and returning the correct hit.collider just for some reason the hit.point is always zero and I dont understand why, for context this is the full line, any additional info to provide or any steps I can take to investigate further?
Physics.SphereCastNonAlloc(transform.position, 1f, Vector3.up, hit, 1f, listenLayers); (this line exists in a script that only has this line, attached to a default cube without a collider for testing)

leaden solstice
soft shard
leaden solstice
#

Actually

Notes: For colliders that overlap the sphere at the start of the sweep, RaycastHit.normal is set opposite to the direction of the sweep, RaycastHit.distance is set to zero, and the zero vector gets returned in RaycastHit.point. You might want to check whether this is the case in your particular query and perform additional queries to refine the result. Passing a zero radius results in undefined output and doesn't always behave the same as Physics.Raycast.

soft shard
leaden solstice
soft shard
#

The wireframe represents the exact pixels of the cast, when the inner circle turns red, and the cube turns green, there is a "intersection" and the NonAlloc result is 1, and the correct collider of this black cube is returned, and the point is zero - by "manually moving the cast" I mean just dragging it in the Scene view toward the black cube until there is a intersection - I also tested with the origin not inside the cube im moving, but maybe I dont understand when or how the sweep works

leaden solstice
#

If collider detected within distance 1 from your transform.position then that’s gonna happen

soft shard
#

Hmm, im not sure I fully understand? So if I wanted hit.point to return a non-zero value, the distance of 1 has to be larger than the transform.position or the collider im trying to detect needs to be further than a distance of 1 from the transform.position? (since 1 in this case, is the radius)

leaden solstice
soft shard
#

Hmm alright, ill play around with that and see if I can get some positive results - thanks for clarifying that up for me

karmic mulch
#

guys I am trying to import a github project from another version of unity to new one 2022

#

and its showing only one error

#

these are the files

#

I have asked chatgpt but i know its not something wrong in the code

#

but something that can be due to the versions and it might be something you guys know

knotty sun
karmic mulch
knotty sun
karmic mulch
#

also i think like this maybe due to something to do with the version

karmic mulch
knotty sun
karmic mulch
#

wait

#

this is the file of the code

#

''' namespace TD.Inputs
{
public abstract class BaseInput
{
protected readonly Controls controls;

    public BaseInput(bool enable)
    {
        controls = new Controls();

        if (enable)
        {
            controls.Enable();
        }
    }

    public void SetActive(bool active)
    {
        if (active)
        {
            controls.Enable();
        }
        else
        {
            controls.Disable();
        }
    }

    public void Dispose() => controls.Dispose();
}

} '''

#

sorry how do i make this code come under a snippet in discord

knotty sun
#

!code

tawny elkBOT
knotty sun
#

use a paste site

karmic mulch
#

!code

tawny elkBOT
karmic mulch
knotty sun
#

also the controls script

karmic mulch
#

aah okay

#

this is the controls file

#

its quite long

knotty sun
#

There you go, they are in 2 different namespaces

karmic mulch
#

what can i do to fix this

#

also how did this happen cause

#

the other person had this project running

lean sail
#

are you modding a project or something?

knotty sun
karmic mulch
karmic mulch
knotty sun
#

do you know what a using statement is?

karmic mulch
knotty sun
karmic mulch
#

in the baseinput file?

knotty sun
#

yes, of course

#

you need to use the namespace that the Controls class is in

karmic mulch
#

using namespace bginputs?

knotty sun
#

so you don't know how to use a using statem,ent

karmic mulch
#

yea i know in general terms

#

like using a library

#

or using the general inputs

#

symstems

knotty sun
#
using BG.Inputs;
karmic mulch
#

i just add those things

#

wow

#

it worked

#

wth

#

chatgpt was showing me lots of things

#

like reimporting and stuff like that

#

i want to ask one more thing

#

how did this could have happend?

knotty sun
#

you really need to go and learn some C# basics before continuing

karmic mulch
knotty sun
karmic mulch
#

just downloaded the project

knotty sun
#

show me the link to the github

karmic mulch
#

and imported

#

it again

#

i think

#

its cause of the importing

#

this is the link

#

this guys is amazing i know him

#

but didnt want to ask more from him

#

about this stuff

knotty sun
#

you changed something

namespace TD.Inputs
{
    public partial class @Controls: IInputActionCollection2, IDisposable
karmic mulch
#

but how do you know from this

#

code?

knotty sun
#

Look at the namespace. I copied from the original on Git

karmic mulch
#

aah it became from td to bg

#

but it might have been done by

#

unity itself

#

not me

knotty sun
#

nope

karmic mulch
#

i didnt even touch anything

#

just downlaoded and started \

knotty sun
#

the code does not lie

karmic mulch
#

😅

#

i know but here

#

i think this controls thing is a culprit

#

or something

#

also the script says it changes

knotty sun
#

Yes, if YOU regenerate, Unity does not do that automatically

karmic mulch
#

i feel still

#

cause i just downloaded it

#

these files are one of the culprits

#

😄

#

also will i approach it as like changing the namespace name in the controls script to tg.inputs

#

instead of adding a using namespace

#

in the baseinput.cs

knotty sun
#

I wouldnt do becuase if you regenerate it will change it back to BG

velvet pebble
#

I'm trying to make a monobehavior whose sole purpose is to display a text box in the inspector for use as documentation. Is there a way to prevent it from being added to builds?

velvet pebble
#
#if UNITY_EDITOR
public class Note : MonoBehaviour
{
    [TextAreaAttribute(3,10)]
    public string Notes;
}
#endif
``` Here's what I have so far. This seems like it'd throw an error if I tried building, although I haven't tested it yet
knotty sun
karmic mulch
#

but yea i feel i would have done something

knotty sun
karmic mulch
#

but i for sure to hell didnt do a typo

velvet pebble
#

🤦‍♂️ forgot about that

#

thanks

velvet pebble
#

unlucky

lean sail
knotty sun
# velvet pebble unlucky

Learn something new every day.
In that case just wrap the declarations in the #if and Leave an empty class for the compiler

velvet pebble
#

thanks for the explanation. I just wanted a quick and dirty way to have notes for myself

knotty sun
# velvet pebble I'm going to go with this

I am somewhat surprised at this, it's a very specific error message so Unity have obviously put some thought into it but I cannot think for the life of me why they would have such a restriction

oblique spoke
knotty sun
swift falcon
#

does anyone know of a tutorial or already existing asset for a nested tooltip system like in ck3/bg3?
i'm trying to create one but the behaviour is so complicated with when to hide and show them when the mouse enters and exits them

thick terrace
# velvet pebble I'm going to go with this

be careful with this, putting serialized fields inside an #if UNITY_EDITOR can cause serialization errors and weird problems in builds, there's a specific error you'll see about this sometimes! not sure if it would affect you in this situation but it's worth being aware of just in case

river kelp
#

I'm making a track with sprite shape and I'd like to be able to access the Sprite shape spline from code so I can use it like a rail, is that possible?

limber fog
#

anyone mind linking me to a tutorial on how to make an interactive world space ui? every answer ive found online is either vague or untrustworthy

soft shard
# swift falcon does anyone know of a tutorial or already existing asset for a nested tooltip sy...

Looking at BG3, it seems that the nested tooltips show when you hover over something that should produce a tooltip inside of a existing tooltip (like an item that has a tooltip to a spell), it seems you press a key to keep the first tooltip open, then when you hover over something in that tooltip, it produces a second nested tooltip, when you move away from that "something" while still in the original tooltip, the nested one goes away - certainly sounds like a very confusing system that will probably involve playing with sort order and generating prefabs a lot, is your issue with detecting the text that should create the second tooltip? And are you using TextMeshPro for that or another system?

swift falcon
#

i've looked into using procedurally generated TMP links and it seems feasible, the problem i ran into was the behaviour: (based on ck3 more so than bg3)
hovering over something that should spawn a tooltip should do so, though it shouldn't spawn the same tooltip again from the same source
the cursor exiting the original trigger for the tooltip should hide the tooltip, but not if the cursor goes into the tooltip
if the cursor leaves the original trigger and onto the tooltip and then back to the original trigger it shouldn't hide the tooltip
if the cursor leaves the tooltip to go to a nested tooltip it shouldn't hide the original tooltip
if the cursor leaves the nested tooltip, it shouldn't hide the original tooltip unless the cursor is outside the original tooltip

there's so much to it, i was able to get most of this working well but then one thing wouldn't work and i'd have to rewrite over and over again

#

the bg3 approach would be easier because it uses a button to spawn the tooltip and you have to click out of the tooltip instead of being based on cursor position

#

might go with that instead

open basalt
#

Hi all, looks like the syntex highlighting in my vscode code isn't working properly? Does anyone know a fix or encountered similar? Not sure why the majority of the lines after

        float alteredDamage = 0;

is white out

steady moat
open basalt
#

ohh is that why? I just switched from visual studio to vs code

#

if that's intended behaviour then Im happy with that haha just not sure if I did something wrong

steady moat
open basalt
#

Ive been thinking about improving the way Im keeping the stats. can you explain a bit more on what you mean?

#
public class Stats : MonoBehaviour
{
    [Header("Character Base Stats")]
    [SerializeField] private float _maxHealth;
    [SerializeField, ReadOnly] private float _curHealth;
    public float MaxHealth
    {
        get => _maxHealth;
        set => _maxHealth = Mathf.Round(value * 10f) / 10f;
    }
    [ReadOnly] public float CurHealth
    {
        get => _curHealth;
        set => _curHealth = Mathf.Round(value * 10f) / 10f;
    }

    [SerializeField] internal float Armour;
    [ShowInInspector, ReadOnly] internal float BlockChance = 0;
    internal bool IsDead() => CurHealth <= 0;

    [Header("Attack Base Stats")]
    [SerializeField] internal float AttackDamage;
    [SerializeField] internal float AttackSpeed;
    [SerializeField, ReadOnly] internal float CritRate;
    [SerializeField, ReadOnly] internal float CritDamage = 1.5f;

    [Header("Body Class")]
    [SerializeField] internal Class Class;

    private void Start()
    {
        CurHealth = MaxHealth;
    }
}

Right now I have just one script that holds the stats for each of the character

steady moat
#

Instead of doing maxHealth += X;
You do maxHealth.Add(new MyStructThatRepresentTheSource(X))

open basalt
#

and the reason for doing it this way is to better keep track of where the stat change comes from?

steady moat
#

Oh, really bad idea to modified the serializedfield.

steady moat
#

Obviously, if you want that.

#

Things like increase MaxHealth Gain by BloodStone by 50%.

open basalt
#

it sounds cool, but sorry I dont think Im understanding the Struct thingy

steady moat
#

Or things like Reduce MaxHealth by X for 5s.

open basalt
steady moat
# open basalt I was thinking to do like a ``` [SerializeField] private float maxHealth; ...
private class Stat 
{
  private List<StatModifier> modifiers = new List<StatModifier>();
  private float current;
  
  public void Add(StatModifier statModifier)
  {
    modifiers.Add(modifier);
    Refresh();
  }
  
  public void Remove(StatModifier statModifier)
  {
    modifiers.Remove(statModifier)
    Refresh();
  }
  
  public void Refresh()
  {
    current = modifiers.Sum(x => x.Value);
  }

  public float GetValue()
  {
    return current;
  }
}

public class StatHolder : MonoBehavior 
{
   [SerializeField] private float maxHealth;

   public Stat MaxHealth {get; private set;}

   private void Awake()
   {
     MaxHealth = new Stat();
     MaxHealth.Add(new StatModifier(maxHealth));
   }
}

#

It really is not necessary, but I find it way easier to implement complex feature when working this way.

open basalt
#

ahhh I see

steady moat
#

Also, StatModifier could be a really generic thing. Personally, I'm not using stat only but every form of "Modifier".

open basalt
#

then after a few rounds or a few modifiers, you can simply look at the List and track what has changed

#

more like what caused the change etc

steady moat
#

Yeah

open basalt
#

and you can have a IEnumrator to remove a modifier thus the reduce X for 5s

steady moat
#

Or make complex behavior that depends on that.

open basalt
#

I see I see, this is super cool haha

#

but then I'll have to rewrite the whole thing.... HMMMMMMM

steady moat
#

If you did not anticipate such feature, you might want to keep what you want for your current project.

#

If you face a wall, knows that there is way to get around it.

open basalt
#

I was a bit annoyed at the way I did the health etc, it's like reading and overwriting a public value

#

was not a big fan of it

steady moat
#

It works for simple game though.

open basalt
steady moat
open basalt
#

yep that makes sense, so almost makes sense to pass an interface as a modifier

steady moat
#

Yeah, an interface could work as well but in this case a base class is stronger.

#

Given that you do not want to have complex object in your list.

#

You would want to have people sending object with lifecycle that you do not control.

thin aurora
tawny elkBOT
thin aurora
#

When you did that it will properly inform you of the invalid syntax you wrote

open basalt
thin aurora
#

Do them again

open basalt
#

Im currently using the preview unity 6, but the visual studio package is updated, should be fine?

open basalt
steady moat
# open basalt question: would you lump every regular stat (max health, current health, attack ...

I usually only have a float for things like that. You could potentially have a variate of a statistic that combine a max value and current value together.


public class ModifiableStat
{
  public float Value { get; private set; }
  public Stat MaxValue { get; }

  public void Modify(float value) 
  {
    Value = value;
    Value = Mathf.Clamp(Value, 0, MaxValue.GetValue());
  }
}

...

public ModifiableStat Health = new ModifiableStat();
public Stat MaxHealth => Health.MaxValue;

open basalt
#

ahhh cool cool

#

Thanks, I think this really helped me understand just general usage of classes hahaha

celest wadi
#

For an idle animation in a FPS, where I don't need to necesarry have the character sway around and just the camera, is it a better approach to make animator component and animation clip or to make it in code by altering the cam localRotation/position dirrectly? I do have some camera animations I want to add, idle, landing, jumping, crouching, mostly just changing the rotation to create an impact of some sort.

steady moat
open basalt
#
public enum StatModifierType
{ 
    Flat,
    Percentage
}

public class StatModifier : MonoBehaviour
{
    public float Value { get; private set; }
    public StatModifierType ModifierType { get; private set; }

    public StatModifier(float value, StatModifierType modifierType)
    {
        Value = value;
        ModifierType = modifierType;
    }
}
public class Stat : MonoBehaviour
{
    private List<StatModifier> modifiers = new List<StatModifier>();
    private float baseValue;
    private float current;

    public Stat(float baseValue)
    {
        this.baseValue = baseValue;
        Refresh();
    }

    public void Add(StatModifier statModifier)
    {
        modifiers.Add(statModifier);
        Refresh();
    }

    public void Remove(StatModifier statModifier)
    {
        modifiers.Remove(statModifier);
        Refresh();
    }

    public void Refresh()
    {
        float flatSum = 0f;
        float percentageSum = 0f;

        foreach (var modifier in modifiers)
        {
            if (modifier.ModifierType == StatModifierType.Flat)
            {
                flatSum += modifier.Value;
            }
            else if (modifier.ModifierType == StatModifierType.Percentage)
            {
                percentageSum += modifier.Value;
            }
        }

        current = (baseValue + flatSum) * (1 + percentageSum);
    }

    public float GetValue()
    {
        return current;
    }
}

Here's what I ended up with, I now have way more control of each stat, very cool honestly hahaha

sharp bison
#

Hello, I made a world space UI but i can't interact with it at all. Anybody know how to fix it, I would greatly appreciate it, thanks!

sharp bison
leaden ice
minor tinsel
#

I am following this tutorial by CLC but when I add PerObjectData.ReflectionProbes my editor immediately crashes. I fixed the crashing by also adding PerObjectData.ReflectionProbeData (it was not in the original tutorial) but the reflection probes seem to not be sampled correctly and is uniformly grey. Anyone else have this issue?

A Unity Custom SRP tutorial about supporting level-of-detail and simple reflections.

wintry crescent
celest wadi
#

I have a very weird problem. The animation rig sometimes become invisible at a certain angle. Animator is however set as Always animate ( in case it would believe it's not on the screen)... anyone had this issue? it's driving me insane

#

thats a 2k bone setup

gray mural
#

Is there any way for a non-MonoBehaviour class to check when it is serialized in the inspector. Or, perhaps, check when this class is added as a List item, since Unity doesn't call its empty constructor, which is my goal

leaden ice
#

What are you trying to do

#

"added as a list item" doesn't actually affect the thing at all

gray mural
leaden ice
#

Constructors run when an object in C# is created

#

Oh wait a non-monobehavior?

gray mural
gray mural
leaden ice
#

I misread

#

You can use a custom editor for the thing with the list

#

To detect when adding a thing to the list

gray mural
#

Yeah, it's not like I cannot track it in the original class

#

Since it has ExecuteAlways, I can track it in Update too

#

I just want to find a way to make the class "trackable" without the additional functionality in its MonoBehaviour holder

#

I have discovered ISerializationCallbackReceiver, but it doesn't work for my use case

leaden ice
#

What's the end goal here

gray mural
#

The list item is added with everything set the its Type's default. I want to assign the default variables myself

leaden ice
#

The default list add actually clones the last entry if it exists

#

I don't think you can really change that without a custom editor

gray mural
#

Thank you for your help, I'll consider using the custom editor then

meager tinsel
#

I'm running into some issues, with this first person controller. It's...allowing me to move the camera up and down, but not any other direction. Additionally, it's not allowing me to move at all, and I'm not sure what I did wrong with it.

tawny elkBOT
meager tinsel
rigid island
meager tinsel
#

Oh, I'm so dumb. I thought I had a serious problem, that was precisely it. Thank you.

worn crystal
#

is there a way that I can view a materials offset in editor without actually applying changes?

#

i have a script that modifies the material offsets at editor time via a script that uses ExecuteInEditMode, but the script ends up modifying the offsets of the material

lean sail
worn crystal
#

would it create garbage?

#

or leak if i do that

lean sail
#

Or just actually create a new material asset and use it temporarily for your editor uses

worn crystal
#

so id probably have to destroy it right before i hit play or something then too?

lean sail
opaque sun
#

how do I call a void in a different script that has its own variable?

#

like i wanna call this

#

public void Missile1UI(float time1)

#

this is what im doing to call it

#

gameObject.GetComponent<HUD_ctrl>().Missile1UI();

#

if I DONT add the "float time1"

#

i get this error:

#

Severity Code Description Project File Line Suppression State
Error (active) CS7036 There is no argument given that corresponds to the required parameter 'time1' of 'HUD_ctrl.Missile1UI(float)' Assembly-CSharp C:\Users\censored\Downloads\Ace combat fangame\Assets\Scripts\Weapon_System.cs 53

#

if I DO ADD IT, i get these 3 errors

#

Severity Code Description Project File Line Suppression State
Error (active) CS0103 The name 'time1' does not exist in the current context Assembly-CSharp C:\Users\censored\Downloads\Ace combat fangame\Assets\Scripts\Weapon_System.cs 53
Error (active) CS1003 Syntax error, ',' expected Assembly-CSharp C:\Users\censored\Downloads\Ace combat fangame\Assets\Scripts\Weapon_System.cs 53
Error (active) CS1525 Invalid expression term 'float' Assembly-CSharp C:\Users\censored\Downloads\Ace combat fangame\Assets\Scripts\Weapon_System.cs 53

potent anchor
#

since the Missle1UI function requires a float (time1), you need to pass it a float.

#

Like this:

#

float timeParameter = 1f;
gameObject.GetComponent<HUD_ctrl>().Missle1UI(timeParameter);

#

(though I have no idea what that parameter actually does, so not sure what value to pass in and randomly chose 1f)

rigid island
rigid island
#

also post code properly its hard to read on mobile

opaque sun
opaque sun
# rigid island also post code properly its hard to read on mobile
Error (active)    CS0103    The name 'time1' does not exist in the current context    Assembly-CSharp    C:\Users\censored\Downloads\Ace combat fangame\Assets\Scripts\Weapon_System.cs    53
Error (active)    CS1003    Syntax error, ',' expected    Assembly-CSharp    C:\Users\censored\Downloads\Ace combat fangame\Assets\Scripts\Weapon_System.cs    53
Error (active)    CS1525    Invalid expression term 'float'    Assembly-CSharp    C:\Users\censored\Downloads\Ace combat fangame\Assets\Scripts\Weapon_System.cs    53```
#

btw these are errors, not code

rigid island
#

but yeah you need to configure your IDE these are very basic c# errors

potent anchor
#

looks like you're trying to call it with the word 'float' in the parameter list. You don't need to do that. It knows it's a float from the method definitoin

rigid island
#

alr well if you haven't , you should still be configuring your IDE. Then would look at the pins in #💻┃code-beginner

opaque sun
rigid island
#

you should redo it then because coding without a configured IDE is a good way to shoot yourself in the foot esp as beginner , syntax , spelling errors etc..

opaque sun
rigid island
opaque sun
#

it can autocomplete getcomponent statements, if that means its configured

rigid island
#

alr then

opaque sun
#

the errors were in VS console

#

not in unity

#

(didnt even save the script yet)

rigid island
#

as long as red underlines show up and the other c# objects like unity ones

opaque sun
#

I used to be so much better at unity, but I forgot alot

rigid island
#

the error was c# specific not unity

#

good to do a crashcourse on c# .
Btw a void is a return value for a function/method. It means it doesn't return any value

#
private void Sleep()```
[access modifier] [return type] [method name] [parameters]
zinc parrot
#

if I have a list of triangles with their UVs
and I have a list of emission textures that those triangles index into
and I am inside an async task
is there any good way to actually see if the space on the texture covered by the triangles is actually emissive?
Currently I have to, out of the task, convert all the emission textures to read/write texture2d's, and then do getpixels on them and store that in a massive buffer(which is horrid for RAM), and then in the task i can "sample" those emission textures for each triangle(all so I can disacrd triangles that are not actually emissive, aka if the space they cover on the texture is black)
This works, but can use HUGE amounts of ram, is there a better way given that you cant dispatch compute shaders from inside an async task?(the triangles created inside the task, and the code that needs that trimmed triangle list is also inside the task)

late lion
zinc parrot
#

yeah

late lion
#

And a texture index for which emission texture it uses?

zinc parrot
#

3, one for each vertex

late lion
#

Okay, so you need to know if any of the pixels the triangle covers is emissive? And the triangles can be any size, covering any number of pixels?

#

or texels, rather

zinc parrot
#

yeah
I need a better way than my current method which uses too much memory(store all the textures into an array of arrays and sample from that per-triangle) that can run inside an async task, aka off main thread

late lion
#

That bit seems like the most complicated, whether it's implemented in CPU or compute shader

zinc parrot
#

doesnt really matter, its aproximate, I think I am only actually checking the UVs directly covered by each vertex and the center of the triangle rn

late lion
#

If you can do this in a compute shader, you could use the area of the triangle to choose the mip level, to save on how many samples you need to do to get a rough average of a larger area.

zinc parrot
#

but I need to make sure the textures are rw/write enabled so I gotta set them to the active rendertexture then do readpixels from that back into a read/write texture

#

and you cant call compute shaders inside async tasks

late lion
#

You could use AsyncGPUReadback to read back a specific mip level of a texture directly to a NativeArray.

#

For dispatching compute shaders inside async tasks, you could implement a thread-safe queue which the main thread checks periodically.

#

UniTask also has await UniTask.SwitchToMainThread(), if that is at all an option.

zinc parrot
#

hmmmmm ok

#

ill look into those thanks!

late lion
#

If you're using Unity 2023.1+, you can also use Awaitable, which has await Awaitable.MainThreadAsync();

meager tinsel
#

Extremely simple kill/respawn script here, with the aim being that you respawn at the last touched point once you hit the mesh collider with the Hazard tag. I've made sure that the hazard had the right tag, and even is set to isTrigger, so I'm not sure what I'm missing.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class KillRespawn : MonoBehaviour
{
    //Variable for the last respawn point the player has touched.
    Transform lastRespawnPoint;
    //This is going to trigger on the entering of a given respawn point, once touched and once they die.
    private void OnTriggerEnter(Collider collision)
    {
        if (collision.gameObject.CompareTag("Hazard"))
        {
            transform.position = lastRespawnPoint.position;
        }
        //When you touch a respawn point, it saves your current progress to that one.
        if (collision.gameObject.CompareTag("Respawn"))
        {
            lastRespawnPoint = collision.gameObject.transform;
        }
    }
}
leaden ice
meager tinsel
#

Oh, sorry. I guess it's not doing what I aimed for it to. Specifically, not respawning the player back to the respawn points that get touched.

leaden ice
meager tinsel
#

I threw in a Debug.Log at the If for the hazard statement, and it triggered, so that's working.

leaden ice
#

and then one inside each if statement

meager tinsel
#

Just putting that in gives me a ton of errors, so not sure.

leaden ice
#

what errors

#

"a ton of errors" is vague and not actionable

#

most likely it's just a simple syntax problem, or you put it in the wrong place.

meager tinsel
#

That's probably true.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class KillRespawn : MonoBehaviour
{
    //Variable for the last respawn point the player has touched.
    Transform lastRespawnPoint;
    //This is going to trigger on the entering of a given respawn point, once touched and once they die.
    Debug.Log($"Collided with {collision.collider.name} with tag {collision.collider.tag}");
    private void OnTriggerEnter(Collider collision)
    {
        if (collision.gameObject.CompareTag("Hazard"))
        {
            Debug.Log("DEATH");
            Debug.Log($"Collided with {collision.collider.name} with tag {collision.collider.tag}");
            transform.position = lastRespawnPoint.position;
        }
        //When you touch a respawn point, it saves your current progress to that one.
        if (collision.gameObject.CompareTag("Respawn"))
        {
            lastRespawnPoint = collision.gameObject.transform;
            Debug.Log($"Collided with {collision.collider.name} with tag {collision.collider.tag}");
        }
    }
}

HEre's the errors.

leaden ice
#

Why

#

naturally I meant to put it inside the method...

#

I said outside the if statements

#

i.e., on the first line of the method.

#

what you wrote isn't valid code, so yeah you're getting a bunch of errors 😉

meager tinsel
#

I'm confused by what you mean by putting it inside the method.

leaden ice
#

do you know what a method is?

#

would it help if I used the term function?

#

This is your method:

    private void OnTriggerEnter(Collider collision)
    {
        if (collision.gameObject.CompareTag("Hazard"))
        {
            Debug.Log("DEATH");
            Debug.Log($"Collided with {collision.collider.name} with tag {collision.collider.tag}");
            transform.position = lastRespawnPoint.position;
        }
        //When you touch a respawn point, it saves your current progress to that one.
        if (collision.gameObject.CompareTag("Respawn"))
        {
            lastRespawnPoint = collision.gameObject.transform;
            Debug.Log($"Collided with {collision.collider.name} with tag {collision.collider.tag}");
        }
    }```
#

anything outside of this

#

is outside the method

#

you put it on the line above this

#

aka, you put it outside the method

#

the { } enclose the body of the method

#

all the code in your method needs to go between those { }

#

so what I meant was to put it on the first line inside the { }

meager tinsel
#

Ah. I still get quite a few errors, though.

public class KillRespawn : MonoBehaviour
{
    //Variable for the last respawn point the player has touched.
    Transform lastRespawnPoint;
    //This is going to trigger on the entering of a given respawn point, once touched and once they die.
    private void OnTriggerEnter(Collider collision)
    {
        Debug.Log($"Collided with {collision.collider.name} with tag {collision.collider.tag}");

        if (collision.gameObject.CompareTag("Hazard"))
        {
            Debug.Log("DEATH");
            Debug.Log($"Collided with {collision.collider.name} with tag {collision.collider.tag}");
            transform.position = lastRespawnPoint.position;
        }
        //When you touch a respawn point, it saves your current progress to that one.
        if (collision.gameObject.CompareTag("Respawn"))
        {
            Debug.Log($"Collided with {collision.collider.name} with tag {collision.collider.tag}");

            lastRespawnPoint = collision.gameObject.transform;
        }
    }
}```
#

if I'm doing this right.

leaden ice
#

the problem is you confused me by using the name collision for your variable

#

it made me thing it was a Collision, which you get in OnCollisionEnter

#

since you directly have a Collider you can do this:

Debug.Log($"Collided with {collision.name} with tag {collision.tag}");```
#

but I would recommend naming your variable better. Something like "other" or "otherCollider"

#

Usually people do Collider collision because they changed from OnCollisionEnter to OnTriggerEnter and didn't bother changing the name of the parameter

meager tinsel
#

Alright. No errors, I'm going to walk into the hazard's box collider and see if it triggers.

#

I'm definitely colliding with the Hazard tag, so the real question is why it isn't teleporting me back to the transform for the respawn.

leaden ice
#

or sorry

#

i see you have a DEATH log already

#

is that logging or not?

meager tinsel
#

It was when I tested it originally

leaden ice
#

and... now it's not?

#

Or it still is?

meager tinsel
#

Oh, it still is.

leaden ice
#

ok it is

meager tinsel
#

The respawn one too.

leaden ice
#

So the code is working.

My guess then is that you are using a CharacterController

meager tinsel
#

Oh, I am.

#

Is that a problem?

meager tinsel
#

Okay. Time to figure out how to integrate this. I...don't think it needs to go into my script for my player controller, but I may be wrong.

broken light
#

whats a simple way to assert Dispose() from IDisposable is called before GC cleans up a class just to make sure i don't forget to call it

#

as project gets bigger its easy to forget these things

leaden ice
broken light
#

yeh but i dont think the dtor will get called if another class references it still of which the dispose function was to clean up references

leaden ice
#

Well you asked about GC

#

it's not going to get GCed until those refs are released either

broken light
#

hm fair point

weary kelp
#

I have a coroutine:
private IEnumerator DoCornerHint() { ... }
and in the same file in a called function I have:
StartCoroutine(DoCornerHint());
but during runtime I get:

Parameter name: obj```
even though `obj` is an overloaded parameter and `DoCornerHint` takes no parameter... I've never had this issue ever...
lean sail
weary kelp
# cosmic rain Share the error details.
Parameter name: obj
UnityEngine.Bindings.ThrowHelper.ThrowArgumentNullException (System.Object obj, System.String parameterName) (at <5580a85131d6485c8bcaf178996ed0c0>:0)
UnityEngine.MonoBehaviour.IsObjectMonoBehaviour (UnityEngine.Object obj) (at <5580a85131d6485c8bcaf178996ed0c0>:0)
UnityEngine.MonoBehaviour.StartCoroutine (System.Collections.IEnumerator routine) (at <5580a85131d6485c8bcaf178996ed0c0>:0)
Globals.Interface.ShowCornerHint (System.String Text) (at Assets/Globals.cs:67)
CameraController.Update () (at Assets/CameraController.cs:17)

cosmic rain
#

Share the Globals.cs !code

tawny elkBOT
cosmic rain
#

One thing that I'd avoid doing(even though it is probably fine in the latest versions) is putting several MonoBehaviour in one script.

#

This could potentially be the cause of the issue

#

Another thing is, I'd avoid starting coroutines via string name.

weary kelp
#

it was a test cuz i tried multiple ways of starting the coroutine

cosmic rain
#

Other than these 2 things I can't see anything that could cause a problem.

leaden ice
weary kelp
#

we just talked about this

cosmic rain
#

Though, the line numbers in the error don't match the code...

weary kelp
#
Parameter name: obj
UnityEngine.Bindings.ThrowHelper.ThrowArgumentNullException (System.Object obj, System.String parameterName) (at <5580a85131d6485c8bcaf178996ed0c0>:0)
UnityEngine.MonoBehaviour.IsObjectMonoBehaviour (UnityEngine.Object obj) (at <5580a85131d6485c8bcaf178996ed0c0>:0)
UnityEngine.MonoBehaviour.StartCoroutine (System.Collections.IEnumerator routine) (at <5580a85131d6485c8bcaf178996ed0c0>:0)
Globals.Interface.ShowCornerHint (System.String Text) (at Assets/Globals.cs:52)
CameraController.Update () (at Assets/CameraController.cs:17)

#

not much help though

cosmic rain
#

I bet it has to do with multiple MonoBehaviour in one file, but maybe I'm wrong.

leaden ice
#

Yeah definitely one MB per file

#

the other thing that could be going wrong here is something along the lines of:

  • Starting a coroutine on a destroyed object
  • Starting a coroutine on a deactivated object
#
  • Starting a coroutine on a prefab
#

Showing the CameraController script might help too

#

I think it's almost definitely the destroyed object thing

weary kelp
#

nah its used on the event system which is never deleted

leaden ice
#

Not sure what you mean by that

#

showing CameraController.cs code will help though

icy depot
#

To avoid ambiguity, i've decided to start using namespaces more. However, I'm not sure about using monobehaviours inside a namespace. I looked it up and people say it sometimes works and it sometimes doesn't, which isn't reassuring. I'm open to new ways to battle class name ambiguity though (I'm thinking of Prefixing my class names but I'm not sure if that's good practice...)

cosmic rain
icy depot
#

oh not MonoBehaviour in itself, like any class that implements it

cosmic rain
#

I'm not sure what you mean, but there shouldn't be any problem. Feel free to use namespaces as much as you like.

icy depot
#

oh, okay!

#

thank you

viscid gorge
#

Is it possible to find the outline of a sprite as a vector array (or similar) I want to get the world space coordinates of the sprites outlines

lucid ridge
#

There is a way on dedicated server to create a command system ? I cant type anything in the console 😅

Anyone know a solution about that ?

hard estuary
viscid gorge
#

Maybe outline is the wrong word here. I mean more like an array of vectors that if connected by a line "outline" the sprite.

hard estuary
oblique spoke
lucid ridge
oblique spoke
orchid ore
#

is there a way to simplify this expression?
return RootTransform == null ? transform : RootTransform;

cold parrot
knotty sun
orchid ore
late lion
orchid ore
orchid ore
knotty sun
late lion
#

But destroyed objects not being truly null holds true for both editor and builds.

narrow sphinx
#

Is there any easy/sensible way to profile build times, particularly looking at shader variants? Or will it be a case of digging through build logs

cold parrot
narrow sphinx
cold parrot
#

profiling would not meaningfully help with that. the problem isnt shader complexity, its the number of variations of the same thing that needs to be recompiled with tiny differences.

narrow sphinx
cold parrot
#

how many shaders are you using in your project? normally you should be aware which are used a lot in many variations from working with the project.

narrow sphinx
#

I can guarantee that about 90% of the variations Unity is compiling are not being used in my project, they're just being compiled as shader features that I will want to disable

tawdry jasper
#

I keep running into the same problem. I have a dynamic scene loader, when the player enters some trigger more of the level loads in. I have a problem dealing with scene defined items or characters in my save system (which is based on serializing as strings and player prefs). If a player moves an item to a different scene, or a character ends up in a different scene, how do I load that from my save file? How should I approach instantiating serialized objects?

narrow sphinx
narrow sphinx
# tawdry jasper I keep running into the same problem. I have a dynamic scene loader, when the pl...

As for instantiating serialized objects, the main thing is to keep static data related to the object separate from any dynamic data.

For inventory loading, I used a kind of database (loose term, not an actual db) that holds a reference to all possible item prefabs, then all the load system does is asks the item database what item it should load in based on the unique identifier saved upon serialization.

tawdry jasper
#

I was thinking something similar is the way. So storing a mapping of a name/path to a prefab in something like a scriptable object asset? I wonder if this is what "Assets/Resources" folder is for? So if all item prefabs would be stored in there they could be simply instantiated/ loaded via a string path? (In my only game so far, I only used resources for loading music tracks)

narrow sphinx
tawdry jasper
#

(I don't mean to prematurily optimize - just for the sake of understanding things: Resources.Load still allows Unity to manage what's actually "loaded", while having a scriptable object somewhere referencing all items is identical to loading all the prefabs in the scene - just not instantiated?

narrow sphinx
#

I can't answer that for certain but I would be very surprised if a single list of prefabs would have any noticeable impact on any modern platform

cosmic rain
#

It would have impact on the memory consumed. Unity has to load everything referenced in the scene. If it means a list of prefabs, then they would be loaded as well, along with all the models, textures and other data they're referencing.

narrow sphinx
cold parrot
#

if you need to manage memory in that way, you should use adressables instead of Resource.Load however, Resource.Load has very little utility for memory management

#

considering we're likely talking about small-ish games here, i'd ideally design and scope my game in a way that i can load all of it into memory and never worry about managing what is loaded, outside maybe terrains and other extremely heavy data.

cosmic rain
#

Yep, it's important not to overengineer your project and avoid premature optimizations.

cold parrot
#

heuristically a game that needs resource-streaming is unrealistic without a > 7-figure budget anyway.

jolly phoenix
#

I don't know if i'm posting in the correct room, but is there a way to remove the window border from a build?

#

not sure if i'm using the correct term here

somber wyvern
jolly phoenix
#

trying to remove the title bar

leaden ice
jolly phoenix
#

alright thanks

leaden ice
#

note this only works for windows

#

because it's only relevant for Windows

sand drift
leaden ice
knotty sun
sand drift
sand drift
rigid island
#

prob apple is a pain to work with

leaden ice
knotty sun
leaden ice
#

borderless windowed mode without being fullscreen is less common

#

and without a title bar

rigid island
#

how would you even move it without titlebar 🤔

sand drift
sand drift
leaden ice
knotty sun
somber wyvern
sand drift
knotty sun
sand drift
#

Then care to elaborate what this means: Mono doesn';t implement OS specific things because it is a cross platform library set

sand drift
knotty sun
sand drift
#

A compile time #IF conditional can do what you're talking about.

#

Either way that wasn't my point in the first place

#

The Unity C# API can obviously figure out what OS it is running on at run time. Which is what I originally said until your brought up the Mono runtime which is of no relevance

knotty sun
sand drift
#

What does any of that have to do with the Unity .NET API implementing platform specific code?

knotty sun
#

Everything, Unity's API can only work with what it's been given. The Mono .Net libraries are platform agnostic and therefore Unitys code has to be as well

somber wyvern
#

Unity can do whatever they want, they can build platform specific libraries or part of the API on top of mono, there is nothing stopping them. Mono is just a library they use to base parts of the engine. There are already parts of the API that are totally platform specific, and they could do the same thing for this scenario (Ie, add a new class for windows specific windowing functions like hiding the title bar)

#

However I think there is some misunderstanding somewhere here between you two causing this

sand drift
knotty sun
#

Let me clarify in case you didn't understand what I wrote. Unity's code must be platform agnostic when using the Mono libraries. obviously when building to a specific platform such as Android (using gradle) or IOS (using Xcode) you can be as platform specific as you want. But if you want to build using the Mono backend that option is just not available to you

wind meteor
#

Hello, I'm working on my game and have a slight issue:
I want to fill an UI Image vertically using the fillAmount. The "formula" I thought of is the following:
percentage = currentValue / maxValue

Now, for anyone, this would be sufficient, but I still have a problem. I want the percentage value to be 0 not when currentValue is equal to 0, but I want the percentage value to be 0 when currentValue is equal to 25. The maxValue is 43, so I need a function that tells me at what percentage of the range from 25 to 43 the currentValue is, but I couldn't find or think of anything yet.
Thanks in advance.

leaden ice
#

But basically just:

(currentValue - minValue) / (maxValue - minValue)```
#

since your target range is 0-1

wind meteor
jolly phoenix
leaden ice
jolly phoenix
#

yeah i was thinking about going back to the first application instead of trying it in unity... i was really hoping to get this effect:

leaden ice
#

definitely a separate application than the main game.