#archived-code-general
1 messages Β· Page 354 of 1
perhaps I was unclear with my wording, when I said "instance" of a base prefab I meant an "Instantiated Instance" of a base prefab.
Alright, modify data, anyway
That is not actually any different
Plus the term instance means that already
Prefabs that are not instantiated do not have instances
doesnt matter you know what I meant, a gamobject which was created with Instantiate(base prefab).
It very much matters that terms are understood imo
In a custom Editor, Awake is called when the script is added, and OnEnable when the script is loaded, both on script compilation and when enabling the object.
Is there any easy way to make a method, called when the script is added, or when the scripts are compiled (to avoid issues when modifying code manually)? When using OnEnable, assigned variables get messed up on object enable.
I have just discovered the CompilationPipeline.assemblyCompilationFinished event, so wonder whether using it along with Awake is the best thing
Hey i have a problem with unity pool system ObjectPool<GameObject>
InvalidOperationException: Trying to release an object that has already been released to the pool.
it seem because my pool is small that I get the same gameobject and he is upset when i release it back again...
https://paste.ofcode.org/wqt238s3JeA3p6T9NJ89Xg
did i do something wrong?
internal static extern void ApplyPropertyModificationToObject([NotNull("NullExceptionObject")] UnityEngine.Object target, PropertyModification value);
is there a way I can see what this method is doing?
(i need propertyModifications to work during runtime, so ima copy some of this code and slap it onto a script)
How are you going to copy decompiled code?
ctrl + c
i cant see the body of it
Because it is decompiled.
soo... is there a way to see the body of it??
Well, there are some files saved in your project, so you have to somehow compile them into the original code. I know neither how you can do it, nor whether it's possible
rip
The thing that I'm sure about is that what you're trying to do it pretty useless!
huh, yeah i was just tryina be lazy and not figure it out
if I use tasks for multithreading, is there a way to not make them be able to run on the main thread?
well yeah thats what making a thread is all about..
but Unity API functions cannot run on anything besides main thread
I mean, if I dispatch like 10 tasks at once, and only have 8 threads
How can I make the tasks only run on 7 of the threads, leaving the main thread alone
wait i think im being dumb
You're calling release on it twice most likely.
But im not ): look at the code
I subscribed and unsubscribe the event on get and release so if the event handler is triggered it must be from an active gamepbject
He means BattleMemberPrefab.OnFaint is prob called twice
could that be so?
I think not because of the what I said above
But im not sure 100%
Because it is the same gamepbject id after all
would you be okay with showing us the BattleMemberPrefab script?
Sure, though I changed the code already to delegate the action π
it looked like that
https://paste.ofcode.org/ySx9VCkrDVJJ8fkwznQ9bE
idk what I was thinking on
could you show me the whole code?
i mean, the script the code you sent comes from
https://paste.ofcode.org/Q63q2jZr5Ny35nRnVU9eDQ
this is the code after my fixes
let me see if i can
This doesnt show where you actually call to release it
It is just defining how it gets released
it looked like that
https://paste.ofcode.org/YRxkePrC3xTxrx6mGz4z6z
and the release was in handleFaintedMember whch triggered by OnFained in the prefab
I dont really have the time to go through all this. It should be pretty simple for you to debug and see if and when you're calling release on these objects though
I did, and it called once per gameobject
You sure BaseBattlePrefab.HandleDeath is called only once?
check it
what is the better design for it? the manager listen to events from the prefabs or pass a function with the logic of "handleFaint" to the prefab?
id need more context, tbh I didnt actually analyzed your code, just looked for a possible error
what does handleFaint exactly do?
Honestly it doesnt sound like you debugged in the release method, where the error would be coming from
release the gameobject
starcoroutine that set the gameobject back afer x seconds
i debbuged the release not the function that triggered the event ):
in that case Id make the manager listen for events from the prefabs if the manager contains the pool
depends pretty much on your context tho
its a pool of gameobject for my team members on the battle
when they die they need to respawn after x seconds
gotcha
in that case, for the single responsability principle, I'd make them invoke an event when they die
the manager would listen to that event and make them respawn
KeyNotFoundException: The given key '0' was not present in the dictionary.
System.Collections.Generic.Dictionary`2[TKey,TValue].get_Item (TKey key) (at <787acc3c9a4c471ba7d971300105af24>:0)
UnityEngine.ProBuilder.WingedEdge.GetWingedEdges (UnityEngine.ProBuilder.ProBuilderMesh mesh, System.Collections.Generic.IEnumerable`1[T] faces, System.Boolean oneWingPerFace) (at ./Library/PackageCache/com.unity.probuilder@5.1.1/Runtime/Core/WingedEdge.cs:366)
UnityEngine.ProBuilder.MeshOperations.ExtrudeElements.ExtrudeAsGroups (UnityEngine.ProBuilder.ProBuilderMesh mesh, System.Collections.Generic.IEnumerable`1[T] faces, System.Boolean compensateAngleVertexDistance, System.Single distance) (at ./Library/PackageCache/com.unity.probuilder@5.1.1/Runtime/MeshOperations/ExtrudeElements.cs:396)
UnityEngine.ProBuilder.MeshOperations.ExtrudeElements.Extrude (UnityEngine.ProBuilder.ProBuilderMesh mesh, System.Collections.Generic.IEnumerable`1[T] faces, UnityEngine.ProBuilder.ExtrudeMethod method, System.Single distance) (at ./Library/PackageCache/com.unity.probuilder@5.1.1/Runtime/MeshOperations/ExtrudeElements.cs:32)
BrushKit.ExtrudeFaces () (at Assets/Source/Script/BrushKit.cs:333)
I'm using ProBuilder Plugin for Mesh Manipulation sculpting but i'm getting this unfamiliar error in runtime
If it's nothing you did code related, then theres not much you can really do about a bug in a package. Try seeing if your package is up to date, or if others had this issue. Maybe it happens in a specific scenario that you did
Though really I'd just abandon probuilder and go to blender if you're having issues. Havent used it in some time but iirc a lot of probuilder functionality is experimental or just straight up crashed unity for me.
I have a weird error, and not sure where to post it. I basically get this :
'Event' is an ambiguous reference between 'Unity.Services.Analytics.Event' and 'Unity.Services.Analytics.Internal.Event' in EventWrapper.cs file, which is part of unity I guess. When i try to fix the error by changing Event to Unity.Services.Analytics.Internal.Event, the file reverts. On windows, after a few times it just stays that way, but on Mac i can't seem to make it stay that way. I can't edit the file at all, because it just reverts back to the old state. It's so stupid. The file is part of Unity push notifications
this is the file :
using Unity.Services.Analytics;
using Unity.Services.Analytics.Internal;
namespace Unity.Services.PushNotifications
{
interface IPushNotificationEventsWrapper
{
void RecordCustomEvent(string eventName, Dictionary<string, object> parameters, int version);
}
class EventsWrapper: IPushNotificationEventsWrapper
{
public void RecordCustomEvent(string eventName, Dictionary<string, object> parameters, int version)
{
Event evt = new Event(eventName, version);
foreach (KeyValuePair<string, object> parameter in parameters)
{
evt.Parameters.Set(parameter.Key, parameter.Value);
}
evt.Parameters.AddUserCountry();
AnalyticsService.Instance.RecordInternalEvent(evt);
}
}
}
i do wish, its my final BSc project that i must finish
can somebody explain what's void start and update, explain it beginner friendly way i don't know how i should use those
did you try reading the comment directly above what you highlighted
How do I need to set up a function in a C# DLL to be called and how would I call it?
Dynamic link library I pressume?
https://learn.microsoft.com/en-us/troubleshoot/windows-client/setup-upgrade-and-drivers/dynamic-link-library
Thanks for the resource! Unfortunately this is C++ and I wrote a C# Dll
Don't have experience with that yet, so I can't help you with spesifics, but I know people use "binding events" as bridges between c++ and c#
The form of DLL I am using was written in C# in Visual Studio
I wrote it in C# beause I'm not as familiar with C++
so it would be C# to C#, but not sure how to make this work
maybe I import UnityEngine? But right now it straight up says "Can't be found"
Hello guys! I am having a couple issues with my player movement, specifically with the wall jump. I have tried to make it so that after wall jumping, I cant move for 0.2 seconds, to make it so that my player can get stuck if they are pressing the a / d key (left and right). However, this does not work for some reason. I have looked over the code several time, and I cant find why it doesn't work. If I wall jump, when not pressing A / D, I can move for that time, but if I wall jump when pressing pressing w and a/d it doesn't work. Here is the code: https://gdl.space/avevinomiy.cpp
Then what did you mean when you said "this is c++"?
the link you sent involves C++ code and how to prepare those C++ Dlls for export
I don't think you need to do anything special really. Just make sure it's public and not internal(these would only be public inside the assembly/dll).
You call the function from a dll just like any other function.
I currently use it like I would for other namespaces. I just put "using dllName" at the top but it says that the type/namespace could not be found. I double checked that it is within Assets/Plugins. How can I resolve this error>?
I think this might be because I've excluded editor in the Plugin Inspector. This is because I use some namespaces like Windows that causes errors in the code when Editor is included
A dll is not a namespace
I see. How would I use it then?
- Make sure it's referenced correctly in the editor. Check it's settings in the inspector
How can I see that it's referenced correctly?
right now it's not throwing errors anymore in the Editor console, but it is in the file.
and when I run it, it hits me with
GameObject references runtime script in scene file. Fixing!
And my code has no effect.
Now not even my script is erroring
it's just a the warning I wrote about above
Share a screenshot of the inspector of the dll, the warning in the console and the relevant code
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
β’ Visual Studio (Installed via Unity Hub)
β’ Visual Studio (Installed manually)
β’ VS Code
β’ JetBrains Rider
β’ Other/None
What about the editor(?) platform?
Is that script from a dll?
No, it accesses DLL elements I made
also, this error just appeared
I unfortunately didn't see when, but I didn't touch anything
For starters config your ide how Aethenosity pointed out
I've already done those steps before
Do them again
It is not configured
I have just done it again
Go to external tools and click regenerate project files while the ide is closed
Just did it, no change to how the file looks
You have the current unity extension from Microsoft, and the c# dev kit one?
If so, make sure there is no error in the vs code console about a missing sdk.
I'd just recommend switching to VS instead. VS code is too much of a headache for what it provides imho.
Not sure where to find the console
no errors in the terminal, debug console, or problems
none of these
Ok, well the configuration is just not taking then. As far as I see, you have done everything correctly
Vs code just shits the bed sometimes
OK lemme switch to VS then
Wait I'm an idiot that's the VS editor
No, that's correct. It's what the guide says
oh I see
I'll move through with Visual Studio then
@cosmic rain @spring creek
What are you trying to do? When does this message appear? Did you actually install VS correctly for use with unity?
I had vs a long time ago, that was just opening a file in vs
I am updating it right now
Was it configured for unity?
every step before updating, yes
Then try regenerating the project files, or even just deleting the sln and csproj files manually
Hello guys! I am having a couple issues with my player movement, specifically with the wall jump. I have tried to make it so that after wall jumping, I cant move for 0.2 seconds, to make it so that my player can get stuck if they are pressing the a / d key (left and right). However, this does not work for some reason. I have looked over the code several time, and I cant find why it doesn't work. If I wall jump, when not pressing A / D, I can move for that time, but if I wall jump when pressing pressing w and a/d it doesn't work. Here is the code: https://gdl.space/avevinomiy.cpp
What debugging attempts did you make so far?
Printing the logs, trying several different solutions
I don't see any logs in your shared code though
no I removed it after confirming the result
Well, what did you confirm then?
So I was printing out CanMoveOnX, to check whether the values were actually correct
and it was giving me less that 0.2,
but still allowed movement during that time
Well, what part of your code is responsible for movement? Did you not check why it works regardless of that condition?
This is the part for L and R movement, and I have no idea why it works despite that condition
Did you debug it? Are you sure that's the code that causes the movement during the issue?
Yeah I don't think its that code, but I have no idea what else it could be. I actually changed to values to > 3, and it did stop the movement, but only if I wall jumped when not pressing A, just W, which is not the issue im trying to fix
You have a lot of other code that could be moving your object. You should make sure that it doesn't run when you don't expect it to.
This is simple debugging. You should be expected to be able to do it if you're asking in this channel.
Ok, ill go over it again
I GOT IT WORKING
Ahh I see now what was wrong XD
It is simple but hard to see
So basically, I was setting the last on wall timer for when I left the wall, however, it didn't regester I had left the wall cause I was pressing A.
So I changed it so that last on wall is when I just try to jump, not when I actually leave the wall
which solves the issue
BTW TYSM for your help
Any idea how to access particleSystem rate over time?
It seems that a lot of docs / forums offer deprecated solutions
I'm getting this error by the way with the code above:
Assets\Scripts\MC\MCController.cs(184,13): error CS1612: Cannot modify the return value of 'ParticleSystem.emission' because it is not a variable
Save it as a variable, change the variable
You can see they do so in the docs
https://docs.unity3d.com/ScriptReference/ParticleSystem-emission.html
is ps.emission passed by reference somehow?
Maybe it's me not understanding C# properly
but in my current understanding, values are typically passed by value and not by reference when initializing variables (?)
It mentions in the documentation
Particle System modules do not need to be reassigned back to the system; they are interfaces and not independent objects.
Classes are reference types btw. Not value types
oh
Isn't PS.emission a struct though?
Are structs passed by reference too ?
So is it like a Unity specific thing?
it contains a pointer to native data
No, itβs still a value
Its properties just call C++ functions
Unity thing
I'm trying to make it so that the minimap rotates with the third person controller direction and the pointer rotates based on the players direction they are facing, although i cant get the pointer to work correctly. it is spinning with the third person controller and i can't figure out why
without code we can't really help you
here you go sorry about that
let me know if youneed more pictures of explanation
So something like
struct PS.emission = {
bool enabled;
float rateOverTime;
...
unsigned long *emissionDataPtr;
}
?
I dont think this will directly work well, you need to convert world space to screenspace most likely the scales aren't 1:1
hmmm is there a better solution that you know of?
more like every single method it has is extern. It has a reference to the ParticleSystem that it probably uses to get the pointer to the native data
let me double check because I did this a while back
no worries
im trying to make a minimap similar to gta 5
cause i like that one so much
yeah just be ready second camera consider performance hit
you're rendering the world twice essentially
most radar maps are just 2D textures anyway
yeah ill mess with the performance aspect later but ima just do this for now
why am i getting 12+ ms while drawing only 10000 instances of a cube using Graphics.DrawMeshInstancedIndirect? what am i doing wrong here?
?what happens if you reference the player instead of armature
How did you time it?
@little meadow did you mean how i got that 12+ ms? i got that from the game stats
that game object doesnt move at all
it just holds it in an organized manor
I see , what are both values when they go offset? UI z vs player Y rot
its kinda hard to tell
it just kinda starts
ill try to get a better video to show you
its like as soon as you start moving and spinning the camera around is when it starts to spin weirdly
and it shouldn't be spinning when the player stands still and only the camera moves around
you might need to account for the minimap camera
what do you mean by that
maybe try cs [SerializeField] Transform minimapCamera; var relativeRotation = player.eulerAngles.y - minimapCamera.eulerAngles.y; pointer.rotation = Quaternion.Euler(0, 0, -relativeRotation);
nice!
this
var relativeRotation = player.eulerAngles.y - minimapCamera.eulerAngles.y;
is very dangereous to rely on, it may not return the values you expect
would it be better to use Atan2 ?
What would I need to do better
probably something to ask @knotty sun I'm not exactly good with rotations π
I was thinking with radians you can do
var playerForwardRelativeToCamera = minimapCamera.InverseTransformDirection(player.forward);
var angle = Mathf.Atan2(playerForwardRelativeToCamera.x, playerForwardRelativeToCamera.z) * Mathf.Rad2Deg;
pointer.rotation = Quaternion.Euler(0, 0, -angle);```
That code has some weird behavior
its like horizontal and rotates but also flips horizontally sometimes
ah yeah then not sure lol
I think
var relativeRotation = player.rotation * Quaternion.Inverse(minimapCamera.rotation)
or Quaternion.Angle will give you the angle difference between 2 quaternions
so you could do
var angle = Quaternion.Angle(player.rotation, minimapCamera.rotation);
pointer.rotation = Quaternion.AngleAxis(angle, Vector3.up);
it's way too early in the morning to be thinking in Quaternion math, lol
same lol 4am here
definitely not something to do with the brain only firing on 2 cylinders
why am i getting 12+ ms while drawing only 10000 instances of a cube using Graphics.DrawMeshInstancedIndirect? what am i doing wrong here?
so my point earlier was that the time from the stats window is not particularly precise usually... I don't trust it... is it 12ms less when you remove this code?
12ms does seem a bit high for this... is it 12ms for the GPU? where do you see it?
12ms coming from where? You should do some profiling and provide a bit more detailed info.
I bet that the main issue is allocating a huge buffer every frame
anyone?
Assuming this is a script from a unity package, you can't and shouldn't really try to modify it. It is likely a version incompatibility.
I'd try checking the version of the package and confirming that it's compatible with the editor version.
why do you have both of these?
using Unity.Services.Analytics;
using Unity.Services.Analytics.Internal;
I can't change them π the file just reverts itself back to the old state
thanks, I'll try it.
how am i supposed to know the compatible unity version for the package version?
You can see that in the package manager as well as in the documentation of the package.
@little meadow it was from this...i found out that instancing all these 10000 cubes at the same place caused that problem, when i spreaded out the positions of all these instances, it is around 1.8ms
Maybe using pre release is the problem? It doesn't say it's incompatible
This is a GPU bottleneck. Might be related to what I mentioned earlier about the buffer. To profile further you'll need to use the GPU profiler module.
thanks man
That could be it, yes. Specifically, there's probably a compatibility issue between this push notifications and the analytics package(or wherever that event type was coming from)
You should check the requirements/installation instructions of that push notifications package.
I updated to a new version, and it's good now. Thanks
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (GameIsPaused)
{
Resume();
}
else
{
Pause();
}
}
}
void Pause()
{
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
GameIsPaused = true;
pauseMenuUI.SetActive(true);
Time.timeScale = 0;
}
i have a couple functions to handle my game pause logic and it works fine for the most part. However, ive noticed that whenever I use this script in any of my projects, and my GameIsPaused variable is a static bool, i have to press the esc key twice for the pause function to execute. When my GameIsPaused variable is not static, however, i only have to press my esc key once and everything works as intended. can anyone share some insight on what might be happening here?
did you disable domain reload on play? if so, you'll have to reset static fields yourself https://docs.unity3d.com/Manual/DomainReloading.html
ah yes, i do have domain reload disabled. thanks i completely forgot abt that
Hey folks, not sure if this is the right place to ask this. But is there a way to import a scene with just the objects & textures into a new project, without any the settings/dependencies/packages of the original project?
I made a big woopsie and accidentally overwrote my original project when experimenting with an asset. I admittedly was being a little hasty, and it ended up installing URP, Burst, Core RP and a bunch of other things I don't want or need. It completely wrecked all my textures and VR stuff, and I have been working for hours to try and remove or reverse the changes with no luck.
I think my best option would be to simply start a new project, and basically import just the scenes/objects by themselves with nothing else, and fix my VR stuff later. (I needed to make some changes anyways)
Is such a thing possible?
I don't mind having to fix up some textures, I just don't want to have to re-import every object one by one and recreate every scene manually if it can at all be avoided
Assets->Export / Assets->Import should do the job, just look very carefully at what you export
You are my hero. Honestly even if I can't get 100% of everything transferred over, you have probably saved me hours of work. Thank you, will update if I get it working
i have chess board like tiles is there a rule tile i can use to place them fast one by 1
Pretty sure it's achievable by adjusting the default rule tile
Also, pretty sure it's pretty useless
I debugged again, and the event was triggered once. But the event handled got 2 eventsβ¦
Seem like the unsubscribe didnt work
alright
also why is my slider ui element behind everything
If your chess board is in non-UI, then the Canvas might be further from the camera than the board
If both are UI, check the hierarchy order
Also, ignore my previous answer for this answer. It's not possible with the normal rule tile
checked and did everything still didnt work
You have to create your own one
ok i wont use the textures
this looks better imo
Why?
they dont look good
How are you going to add textures to your game without using textures?
No Iβm gonna use the current one u see
I checked it called once once, but still i get 2 triggers on the handler ):
You checked if the event is only called once?
show your subscribe and unsubscribe code
yes
@grizzled ferry @knotty sun i found the issue. because i needed to pass the gameobject i want to release to the handler i used anonymous function so it didnt unsubscribe it
i fixed it by changing the event to Event<GameObject>
Does anyone know how to cap an application on 40 fps on 60hz display device - I know its possible some game are doing it and it works on both iOS and Andriod but i am unable to do so using unity ,any help or any suggestion towards that direction would really help
please dont say i will need to get enterprise license
and also
Application.SetTargetFrameRate(40); this will cap game to 30fps on a 60hz mobile and will only work in 120hz mobile
OnDemandRendering API is something you might be looking for? https://docs.unity3d.com/ScriptReference/Rendering.OnDemandRendering.html
There's also Adaptive Performance to respond to power/thermal/battery conditions on a higher level
`using UnityEngine;
using System.Collections;
using System.Threading;
public class CustomFrameLimiter : MonoBehaviour
{
[Range(10, 144)]
public int targetFrameRate = 40;
private float targetFrameTime;
private float lastFrameTime;
void Start()
{
ApplyFrameRate();
StartCoroutine(FrameLimiterCoroutine());
}
void ApplyFrameRate()
{
targetFrameTime = 1f / targetFrameRate;
QualitySettings.vSyncCount = 0; // Disable VSync to use custom frame rate
}
IEnumerator FrameLimiterCoroutine()
{
while (true)
{
float currentTime = Time.realtimeSinceStartup;
float elapsedTime = currentTime - lastFrameTime;
float timeToWait = targetFrameTime - elapsedTime;
if (timeToWait > 0)
{
// Introduce a delay by waiting until the target frame time is reached
Thread.Sleep((int)(timeToWait * 1000)); // Convert to milliseconds
}
lastFrameTime = Time.realtimeSinceStartup;
yield return null; // Continue to the next frame
}
}
}
`
how about this code?
would this help in performance in low end device?
like i want my application to be capped at 40fps on 60hz display wouldnt ondemand render just change render speed
Not throttling the device would help if that is what you are seeing, yes
can you explain how would i do this
does this code looks fine to you?
Install the adaptive performance package and configure it
Unity has various APIs to better work with mobile devices
see i want players to have option to change fps as well i dont want it to be fixed but i also want a 40fps mode ( currently im provviding 20-25-30-40-60 fps mode) but 40 fps is not working
will adaptive performance help with this?
It will help for the reasons you are most likely doing this frame limiting. Just setting a framerate and having users pick can be a bit naive in the mobile world.
Engine rendering speed and screen refresh rate is something you might want to think about separately.
people like to choose it
and moreover i can cap FPS based on device specs
like you can only get 40 fps on x device but if you want you can play in 20fps as well
should i be using my script?
Hello, I have problem with audio mixer, I am trying to set value of it from player prefs in awake but then something (I read it a snapshot) is overriding it. If player set volume values I would like to have them from start, not after their ears are blasted off.
Am I doing something wrong or is there work around?
PS: Pls @ me
I dont think you need a mixer for volume, you can normally set the volume on the AudioSource directly, or if you want all your audio sources to always have the same volume you can also set AudioListener.volume which is a static value - if you do prefer to use a mixer, AFAIK you should either use exposed properties of your filters, or a "snapshot", though I havnt needed to use snapshots with my mixers, I usually just make a "group" instead and control the "attenuation volume"
I am using exposed parameters and tried to keep them in player prefs between sessions. I'll look into using snapshot or groups. Thanks
COMException
Rethrow as AssimpException: Error loading unmanaged library from path: assimp.dll.
Does anyone have any ideas to what might be causing this error. The lib works fine on my computer but when someone else tried downloading the repo and opening and running the project he got this error
Sounds like the compiled library (dll) isn't compatible with their setup
how would i go about debugging the issue
I've got a problem:
Timberborn stable: full FPS, even with over 200 beavers and at 33x speed
Timberborn experimental: 1-2FPS with just 10 beaver at 3x speed
7950X3D. If I launch it in steam with the command
taskset -c 0,2,4,6 %command%
everything seems to run perfectly right, full FPS at all times
This is the Unity game development server for discussing the idea of making games. Maybe you should contact the developer of that Unity game.
I did contact some devs of Timberborn
I was wondering if this is a general Unity problem or some problem with how they wrote the Timberborn game
I was hoping to get a bit of answers here that I might be able to share with Timberborn devs
or just with people who experience the same issue, as I personally know at least 10 people so far that have this exact same problem, and i hardly know anyone
we dont have access to profile the game, and really even if we did its doubtful anyone here really would take the time to do so
understood
Hi! I'm struggling with writing Play Mode tests. I have a script that calls Screen.height. It works in the editors Play Mode, but not in Play Mode tests. There it gives a null. I'm loading a scene in {Setup] with SceneManager.LoadScene("TestScene", LoadSceneMode.Single). Why is Screen null?
Dont crosspost
I'm unsure if you are trying to achieve something specific. But it is probably easier to use the built-in Application.targetFrameRate value
They have been working on this for a while. They know about that property already. It does not work as expected, and will cap to 30 when entering 40 (when done on a 60hz device, it works properly in a 120hz device)
what's the diff between code beginner code general code advanced?
The difficulty of the question and your own level. If you know how to do debugging properly(with logs, debugger and visual queues) and still can't solve an issue, #archived-code-general would be a fitting place to ask. Otherwise #π»βcode-beginner .
#archived-code-advanced is ambiguous. When you have a question worth it, you will probably know it.
Anyone know of a good unity asset for handling large volumes of text that is not dialog i.e Mission Text, Item/group/concept descriptions in in-game wiki, journal entry, etc. So far the options I've found are focused for dialog rather than like Text Content.
Have you looked at a markdown parser that outputs ui toolkit markup? That still needs some customization (the ui toolkit output) but it should do most of the heavy lifting. https://github.com/xoofx/markdig
Hello, while working with System DLLs, Unity Editor crashed, and I got this error in the Editor.Log.
Can someone please help me? I'll give any context I can. This has been bugging me for so long. Thanks for any help!
show the inspector of the used dll
Are you building using .Net FrameWork or .Net Standard
ok, can you check the dll to make sure it is .Net framework 4.7.2 or below
and see what dependencies it has
I'm a bit concerned with the Windows.Devices.Bluetooth. I'm pretty sure Mono will not support this
i keep on getting this errror even tho there are no duplicates of upadtes
in my cosde
looks like a duplicated script, you have 2 of them in your folder
soh ok
Why is the game object I tagged as something returns "Untagged" when I get its tag?
Most likely interacting with the wrong object. Note that children/parent don't necessarily have the tag.
Does it have a parent with an rb up the hierarchy?
Or a child object with another collider
Then you'll need to share some code and debugging info.
Of course
void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log("Collision"); //Does show up upon entering
Debug.Log(gameObject.tag); //Returns "Untagged"
if(gameObject.tag.Equals("Shell")){ //thus, this does not trigger
Debug.Log("Hit");
health -= 1f;
healthBar.transform.localScale = Vector3.right * health / 100f;
}
}```
Add a second parameter with this to your debug logs.
Hum, what's the point, will do but
Btw, the second log returns the tag of the object that's executing the code. Not the one that collides it.
Oh
Do it and you'll see for youself
I must have messed up
I am tired
I should not do this
Let me hide in a corner π₯²
For info
if(collision.gameObject.tag.Equals("Shell")){ is what I really wanted
Yuuup
The shame is immeasurable
π
Also
healthBar.transform.localScale = new Vector3(0, 0.2f, 1) + Vector3.right * health / 20f;``` was the proper code for the health bar (ignoring the hard coded values)
https://docs.unity3d.com/ScriptReference/GameObject.CompareTag.html
you should use compare tag
Interesting
i was playing saints row 2022 the other day. how does the different voice pitch thing work? they basically had accents(Voice 1, Voice 2 etc) and then you had a slider to set the pitch and it was pretty brilliant
Its just a multiplier for the pitch. Nothing more complicated than that I would assume.
ow alright xD
Yo ! I want to make a game with a horde of enemies, first I tried using the NavMeshAgent system but this doesn't really work because they can't really avoid each others, should I make my own system of pathfinding and is there common process for making horde ? Thanks !
I would suggest that if your agents are not avoiding each other correctly then you have not set up the system correctly
Ok, how would you go about setting up the system ? I tried many differents ideas and nothing was good enough
Therefore I'm here asking
First explain exactly what problems you are experiencing
Ok
I want my enemis to find the path to my player. I'm doing that by calling SetDestination to the player position every x seconds. The problem with that is that they don't collides into each others, therefore they stack in one another. I tried using NavMeshObstacle and .Move or .AddForce but this cost too much performances because CalculatePath is synched. I also tried to put a rigidbody and let the agent move but this also doesn't work and creates strange behaviours. I just want my enemies to move to the player without merging into each others
And for the rigidbody the problem is that they push each others and I don't want that
Sorry but that makes no sense, if you have 20 enemies and they are all told to converge on the same point, of course they will stack up, what are you expecting them to do?
Sorry English isn't my main language. Take for example when there is a crowd of people going into the subway they will slow down if there are in the middle of the crowd, but they will still move forward
That's what I want
In simple terms I want collision that's all
But I don't want my enemies to push each others
Sounds like you want a Raycast which reduces agent speed
Isn't a raycast going to cost too much performance ?
nah
I have an idea but I'm not sure if it's possible, is it possible to make rigidbodies not push each others ? If it's possible I could put a rigidbody on my enemies, this will make them move slower when they hit another enemy ?
but you want to slow before the hit do you not?
A trigger collider could also do that
Not before, I want them to stop if they can't move in the direction to the player
or slow down if they can't move at full speed in the direction to the player
did you nat say
'they will slow down if there are in the middle of the crowd, but they will still move forward '
Yes
so slow down BEFORE they walk into someone, as you would irl
If you're using raycast yes, if you're using physics no
raycast is physics
Ok, but by physic I mean rigidbody
trigger collider could also be used
But this mean I will need to move them manually right ?
But CalculatePath is not performant at all
no, setdestiniation would still work
that you can stagger using a coroutine
But when moving manually and using setDestination there is a desync between the agent movement and the actual gameObject movements
you dont need/want accuracy only reasonable
But I saw that it wasn't safe to do that because of Unity system, is that right ?
no
Ok
I will look into this then
My game is in co-op, this will not cause any problem ?
I think you need to sit down with a clean project and play with the NavMesh system untill you understand it
I would still recommend implement this is a clean project so you can play with the settings without affecting your main project
no, that would completely negate the point of using the NavMesh system
What
I need to move it with something else than the agent if I want it to slow down ?
Oh I can just set the destination to be somewhere else
no you do not, you can control the agent speed
Iβm working on a character editor and it works by generating a png file inside a folder. When I generate it inside of Resource folder, I can access it via the editor but not the built solution but when itβs in any other folder such as StreamingAssets, it doesnβt save as Texture2D rather as a default asset. Any advice?
Save it to any folder at runtime, e.g. somewhere inside https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html. Use https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequestTexture.html to load it into memory at runtime from the filesystem.
You were hoping to rely on the editor's asset import pipeline which naturally does not exist in the built game.
Yeah I tried the persistent data method too but because it doesnβt save in a folder anywhere in the editor, I canβt access it
wdym you can't access it
The method that equips a skin onto the character requires the png file to be in a file somewhere accessible within the editor
That's really vague
But sounds like something that can easily be worked around
regardless, your approach to loading images at runtime cannot involve the asset import pipeline, because it doesn't exist at runtime.
and what makes you think persistentDataPath is not available in Editor?
Because I looked for the generated image and couldnβt find it anywhere
then you didn't look very well
Have you tried looking in Application.persistentDataPath
Anyone non-sound designers here have any good resources/tutorials for integrating WWise for their team's sound designer?
#πβaudio would be best for that
my bad
I'm wondering what is considered best practice?
Option 1: Have all UI Panels(ex PauseUI ) part of the GameManager and just Enable/disable as needed .
or
Option 2: Save UI Panels as prefabs and load/unload on demand.
Keeping them in and disabling them seems like it would be quicker for the system to access, but means they are always in memory, where as loading/unloading saves memory it could eat up some CPU when swapping them out. Seems like its a matter of Memory Optimization vs CPU optimization. Which is considered best practice? if there is one?
edit: clarity/typos
tbh, there is usually nothing in UI which is performance critical, so memory is more important than cpu usage
thats a good point
I guess I'm worried loading/unloading UI's, when pausing could cause a bit of a delay... if I hit the pause button, I want it to pause NOW not in 3 seconds... but maybe were talking fractions of a second so maybe it's not an issue.
3 seconds is extreme, 3 milliseconds might be closer to the truth
yeah that's what I figured.. thanks for your input.
rule of thumb, any thing that takes < 200 ms is considered as instant by the human eye and brain
so i should add a 199 ms delay between every frame in my game for better performance?
I think you're thinking of ΞΌs not ms, 200ΞΌs. A 60FPS game has about 17ms between frames, and while that might be pushing the end of visibility I can definitely tell when something happens within 12 frames. You might be thinking of reaction time, which is different than perception time.
I followed a guide on procedural generation but the function doesn't change my mesh's verticies at all. Someone got a clue what is wrong? ``` private void UpdateMeshVertices(float[,] heightMap)
{
int tileDepth = heightMap.GetLength(0);
int tileWidth = heightMap.GetLength(1);
Vector3[] meshVertices = this.meshFilter.mesh.vertices;
int vertexIndex = 0;
for (int zIndex = 0; zIndex < tileDepth; zIndex++)
{
for (int xIndex = 0; xIndex < tileWidth; xIndex++)
{
float height = heightMap[zIndex, xIndex];
Vector3 vertex = meshVertices[vertexIndex];
meshVertices[vertexIndex] = new Vector3(vertex.x, this.heightCurve.Evaluate(height) * this.heightMultiplier, vertex.z);
vertexIndex++;
}
}
this.meshFilter.mesh.vertices = meshVertices;
this.meshFilter.mesh.RecalculateBounds();
this.meshFilter.mesh.RecalculateNormals();
this.meshCollider.sharedMesh = this.meshFilter.mesh;
}
}```
The brain reorder events that are happening closely. If you click on a button, and the event happens 100ms later, you will feel as you clicked and it immediately happened.
although if theres a delay between clicking and the click sound playing then you will immediately notice that theres a delay (happened to me)
Then the delay was higher then 100ms
I just reread some of the article and it seem like with sound it is possible to feel a dissonance in some circumstance below 100ms. And, 100ms is really the hard floor, in practice 100-200ms is acceptable.
should i use unity's c# style guide even though i prefer google's visually?
googles?
because i'm guessing all of the UnityEngine stuff is written according to the unity style guide
Microsoft is probably who you should look towards...
not google
I know they wrote it, the code just looks uglier to me
(specifically braces on a newline, it's just a waste of screenspace imo and detaches the if/while/whatever statement from the block)
There used to be an API to write basic text onto the screen, I think you could also draw lines and it didn't require any components. It was before unity 4.6 GUI introduction.
I can't find the docs but I'm sure it's still around. Any idea?
Stick to whatever you like, just try to be consistent
You mean IMGUI? It's still there
gotcha ty
Awesome. thank you!
FYI you can do the same with UI Toolkit now too (newer than the 4.6 GUI stuff)
Okay, great. I'll take a look around
should i declare a variable in <object>.Update()?
on one hand, it'll redeclare the variable every frame, which might have performance issues (not sure)
on the other, it's a better scope for it to be in
it's a better scope for it to be in
This
declare your variables in the smallest possible scope
"redeclare the variable every frame" is not a concern for performance
one of the very common mistakes beginners make is not using local variables enough.
yeah, it makes more sense, just wondered if it affected performance
good to know, ty
It doesn't
But using unecessary heap memory by making unecessary member variables can
Can anyone explain why this script is also setting the "Deck" parent as the first sibling of it's parent (the game canvas)? It's causing my deck to dissapear.
public void ShuffleDeck()
{
List<Transform> cardList = new List<Transform>(GetComponentsInChildren<Transform>());
int n = cardList.Count;
System.Random rng = new System.Random();
while ( n > 0 )
{
n--;
int k = rng.Next( n + 1 );
Transform value = cardList[k];
cardList[k] = cardList[n];
cardList[n] = value;
Transform siblingObject = cardList[n];
siblingObject.SetAsFirstSibling();
}
Debug.Log( "Deck shuffled successfully." );
}
Because GetComponentsInChildren<Transform>() will also return your own Transform
Ahh that's what I was guessing was going on. Any ideas for a workaround?
- Exclude it from the list with Linq
- Build your own list using childCount/GetChild instead of GetComponentsInChildren
- don't derive the list from the Transform hierarchy in the first place
Any of those
it is exactly 4.7.2
its dependency namespaces are Windows.Devices.Bluetooth, Windows.Devices.Enumeration. The file works in Visual Studio with just windows.winmd and system.runtime.dll
If mono will not support this, will il2cpp?
p.s. - GetComponentsInChildren is also going to find the grandchildren too
Will do. Thanks!
it's just not a good idea here
oh, yikes
so probably the second one
Sorry if Iβm posting in the wrong channel. I watched Codeerβs video on how to make a procedural animation character. I need a bit of help with the second step of the video, which involves fixing the bottom of the leg to the ground. Any help is appreciated.
henlo people
so if I want to use an interface
I would have to make the function public?
Interface members are required to be public in the class that implements the interface, yes.
You don't need the public keyword inside the interface itself, it is implied.
This make sense?
List<Transform> cardList = new List<Transform>();
foreach (Transform card in this.transform)
{
cardList.Add(card);
}
yes
thanks
yes you can
List<Transform> cardList = new();
foreach (Transform card in transform)
{
cardList.Add(card);
}```
like this
and no need to put this.transform
how bout dat! Thanks, I changed it. Surprised VS didn't give me a heads up to do so
yup that worked too. Thank you!
you can also do List<Transform> cardList = new(transform.childCount); to ensure the list has the right capacity
this may be slightly more efficient
based
so that's no good, in a multiplayer game
likewise an array could be used, but now we're just going crazy
usually public functions are open to be hacked, no?
no
public functions have nothing to do with hacking
C# access modifiers are not protections against hacking
no?
they are only there to help you write good code
Wouldn't that cause the computer to do more work? First it finds the total, then adds them, rather than just adding what is there? Sorry to 'argue' just looking to learn
they don't exist at runtime at all, only in the compiler.
I thought public functions could cause issues, easier to be accessed
ah... huh
interesting
XDDDDDD
When you create a list it creates an array inside of a certain length. It guesses, maybe makes a 10 element array. Once you add the 11th element it has to make a whole new array (probably size 20) and throw out the old one, copy everything over, etc..
By giving it the capacity up front you never have to do that throwing out of an array and copying over part.
Oh dope. Good to know, as my game will involve a few arrays so thanks!
c: good luck with that Inmortal
anyways, is this how I should make the interfaces?
a separate script and put them all there
Thanks m8! Imma need it
There's no need for the Interfaces class
Just make IBreakable.cs and put the interface in it
get rid of the rest
I personally would rename the file too but the filename is completely up to you.
Unlike MonoBehaviour classes, there is no requirement for the filename to match the class name here
IDK, are you planning to put more in this file?
Outside of Unity, the convention is one type per file.
So here you'd have one IInteractable.cs containing just interface IInteractable, and one IBreakable.cs containing just interface IBreakable.
It surely has to read more files, but it's negligible compared to spinning up the compiler process and feeding it all in
except when you have Foo<T> : Foo
I've seen some name them Foo`1.cs, as it would be displayed in ToStrings
some admin will love that person to death
Personally I much prefer many types to a single file, as I hate dealing with file navigation
Plus I just like having types in context to other things around it, such as a bunch of ecs components.
to me it makes good sense if you're not doing OOP
ah
this is not really coding, not sure where I should put it but
how do I add this package to Unity?
it only searches for package.json
This is a question for #π»βunity-talk
But packages are imported from the editor via Assets -> Import Package
nice, thanks!
I followed a guide on procedural generation and for some reason the heightmap wont affect the verticies on my plane. Someone knows what I did wrong?
"0 references" indicates the usage counter - make sure you call this method at some point!
notice its also grayed out color on function (darker yellow)
and 3 dots telling you method is unused
if mono does not support this then IL2CPP will not either as it is based on the mono dlls
how would you check if an enemy is Infront of you
Like an enemy you already have a reference to, or any enemy?
and what's your definition of "in front of"
sure but like
if the enemy is 1000 yards away and behind a wall, are they still "in front of" the player?
like Vision cone?
I combine DotProduct with Raycast
or are we talking about a small area directly in front of the player
If you want a vision cone with a limited range you can start with Physics.OverlapSphere with radius x, and then do a bool withinCone = Vector3.Angle(transform.forward, directionTowardsEnemy) < angleThreshold; to narrow it down
ok ill try that
well frick
hello I made this code to know if a bool of my animator is true or false, how can I do to know if a trigger is active or no ?
public int IsHigh()
{
return Fps_animator.GetBool("IsHigh") ? 1 : 0;
}
you can check animation name
Why would you convert a perfectly good bool into an int???
anyway what's the use case here?
Why do you need to read bools and triggers back from your animator? What's wrong with a normal variable?
my game is multi-player and work with a websocket so it's easier to send the information as 1 or 0 instead of true or false
wouldn't a typical network framework have some capacity for animation syncing?
I wan't to send to other player my current state so they can play the right animation
which network framework are you using
websocketsharp
using websockets sound like a nightmare here
that's not a game networking framework that's a websockets implementation
I don't really unterstand what you mean (my english is not that good π )
it's not that hard π«
eh much easier to use Netcode as it has components to sync stuff for you
it was literally built for the job
yes but it was not fun enought π
also I already tried net code, but i don't really like the way it was working , i really want do everything from scratch to unterstand everything I made, also I've learn a gigantic amount of knowledge
what's that ? will it only detect when the animation is playing ?
this will return true if its playing the clip by name, aka a state
typically you place it in Update if you want a bool to update realtime
eg
Jumping = m_Animator.GetCurrentAnimatorStateInfo(0).IsName("Jump")
I mean. Consider the issue you are having right now
In my animator, I have a βShootβ trigger that can play 3 different shooting animations depending on the situation, so I'll have to check for each of the 3 animations?
technically it's not a problem directly with the server π
Is there a way to lock the cursor in the same spot without hiding it?
ik about Cursor.lockState = CursorLockMode.Locked That is not the functionality I want however:
essentially on the drag i want to rotate a model around based on the mouse inputs (which is already working) but the mouse will still move around I want it to be visible but not move around. Everything I am finding online is just locking and hiding it which also puts it in the center of the screen. How can I accomplish this?
try to add this :
Cursor.visible = true;
Cursor.lockState = CursorLockMode.Locked automatically hides the cursor regardless of Cursor.visible, it also locks it to the center of the screen which I don't want
yes. or you can only track when you called the trigger, doesnt give you the length unless you use the check i showed you
ok π
you want the cursor to be lock but not in the middle of the screen ?
correct, and visible
WinAPI?
you'll have to port it manually to each platform you want though
alternatively you could have a virtual cursor
(hardware cursor is invisible, but you have a controllable in-application cursor)
yikes
i was honestly avoiding installing the new input system π guess I'll have to for this
avoiding it because it looks complicated/hard to learn?
No, I have used it before, theres just no need for it in my current project
i thought the new input system comes with unity now
i dont think so I tried importing it
What does "no need" even mean?
just switch it to a fake cursor when you are rotating
It is just an input system. It should just be standard
its locked anyway, lag will be unfelt
It's in some project templates. Not in others.
probably the default in Unity 6 I think
the problem is when the lockstate is locked, the mouseX and mouseY axes no longer get detected
which is what im multiplying to rotate the model
don't lock the cursor then
make it invisible and confine it to the window
show a stand-in cursor to represent it
pretty sure it still does..doesn't it..
alright Ill try that
no I wouldn't be here otherwise π
all my FPS is locked in middle I can use GetAxis just fine
ah i lied actually
the problem is that i only want the rotation to happen when hovering over the raw image, when its locked in the center it will no longer rotate
im not sure how any mouse movement controller would work if mouse delta didn't work while locked
yes correct I was mistaken
so the cursor goes on image , it locks cursor and it moves in the middle causing the cursor to be no longer hovering ?
yes that is accurate
something about this seems paradoxical
how so
im not really understanding your goal i guess
you want to rotate something while hovering but lock it to what exactly?
lock the cursor to be on the image I suppose
but if its locked how will you stop hovering over it
yes like I don't want the cursor to be moving around while rotating the model around
cause locking snaps it to the middle iirc
so hovering and clicking?
like holding down a button?
because otherwise i don't see how you would stop rotating
yes dragging
oh okay
I can send the script if it helps
it is a bit of a pardaox problem with hardware cursor
if you dont lock the cursor while you rotate it moves away too
either way the cursor will move away , you could use a bool but when your done rotating your mouse is somewhere else
I'm thinking of a solution like:
when click on rotateable object:
swap to virtual cursor
hide and confine hardware cursor to window
while holding drag button:
use mouse delta to rotate
show and unconfine hardware cursor
is there a way to confine the cursor to just the image bounds
not built-in no
each OS handles cursor different
thats not the functionality I want anyways but its a pseudo solution
iirc new input system lets you snap cursor to specific point
could be used after swapping from faux cursor
ah yes there it is
yeah that was my initial thought lol
this should handle each desktop platform
again didnt want to use new input system but I will try using that
i would get used to using the new one, i dont think there's really a good reason to use the old one anymore besides compatibility
the new input system is not that much different than old input system
you can still use it with polling as you're used to
although events are better ofc
i still do polling sometimes because im lazy π«
this project I started a while ago so I am just trying to finish it and push it out its already mostly done and uses the old so call it sunk cost if you want but I don't feel like switching it π
with Get Axis though you do need to just read v2 of mouse
you dont have to switch completely , you can slowly migrate it
set the Player Settings to use Both input systems
I just did lol
isnt osu open source?
you should be able to reverse engineer exactly how mania detects hits
plus: it seems the codebase is mostly C#
oh sorry, ENTIRELY C#
this is for the experimental rewrite of osu iirc, it still might help though ty
what's the maximum lenght for for an Index because It seams that this is too long :
int Index8 = queuedMessage.IndexOf('IsWalking');
and also, does having longer Index really slow the process ?
use " instead of '
using ' around letters is for a char, which is just a single character, but you have wrapped 9 letters in it
oh ok ! thx π
does having longer Index really slow the process
profile it and see if you're specifically having issues, of course searching for more characters will take longer than searching for 1. This is all done so fast though you'll never notice
i find it odd you need to parse anything like this though
Out of curiosity, where would ` be used?
I don't see why " wouldn't be used in its place
When you have a single character
A char is a primitive, so use it over string when you can
the character in this message is a backtick, it would not be used for anything in c#. the character used in the code is an apostrophe which is used for a char literal
that because I making a multi player game with a websocketsharp server , and other player information arrives in this format :
(63ecf009b7a74979bdc8582aac0ab8f9)GID123X-1,037964Y1,296136Z3,7!89,9RIsAiming0IsWalking0IsRunning0IsHigh0IsShooting0IsReloading0$#
So I need to exctract all important information in the message
I mean, that is it. That is the only time to use it π€·ββοΈ
Fair enough lol
why do you send the information like that instead of serializing it to json or something? then you don't need to manually parse the info, you just deserialize it in basically the same way you serialized it
because I didn't know it was possible and also because I'm a terrible programmer and I wanted to do it the easiest way π
that is objectively the "hard" way
it looks like your data is pretty simple so you could literally just use JsonUtility which is built into unity for serialization
I know, but it's one more thing to learn and also I don't have anyone to really guide me and explain to me how to do it right so I do things the way they seem to work, not the way they should be. Honestly, if I'd known it was possible I'd probably have done it that way, but now that I've done everything with my method, I don't think I'll change for the time being, since it's working pretty well.
will it really change something in the performance, because if I change I have to change most of my script π
only way to tell is by profiling it. but it will mean you don't have to do some crazy manual string parsing that will be more prone to error if you don't cover all possible edge cases
I'm working alone, and i spend to much time doing this way and I think it's working pretty ok, Maybe in a next project I will try to improve this part by doing your way !
and i spend to much time doing this way
sunk cost fallacy. it is almost always better to learn to do things right even if you already have something that "works"
my rule of thumb: if its not done in 2 weeks (in some rough form), its not gonna be done in 2 years either.
you're right but that means to do everything again like start again after 500h of work (also it's the 3rd time I'm making this game because the 2 previous versions were poorly done π )
I'd still go and see if changing the method would be possible without modifying my server and client too much
do you want to spend another 5000h and still have nothing?
no why ?
Now I have something that work, it's not finished but it work
why would changing how you are interpreting the data sent across the network be a waste of 500 hours of work? learning how to use jsonutility takes like an hour at most. then implementing it is crazy simple too
If someone is free to allow me to screenshare to show this issue that would be great just lmk. I dont think there is a way to show enough code or inspector screenshots to really show my point
it is incredibly unlikely that anyone would be willing to help you privately like that. just describe your issue using the guidelines in #854851968446365696 as best you can and if someone wants to help then they will do so here
!code
π Large Code Blocks
Use 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 format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Sounds good
because here I was speaking just about the message that update each player of the game. But in reality I have a lot of other message that do other things and that are treated In lot of different way, but maybe you're right and making the change won't be too long
#archived-code-general message
This is what happens when people try to make everything from scratch. Theres only 3 use cases for ignoring all frameworks that exist so you can make your own.
1, none of them have a specific functionality that you need, and it cannot be easily added.
2, you're trying to learn, not really trying to publish something
Or 3, you think it's easy (and are wrong)
I don't say it would be easy I say that it would be easier (for me) also it's an incredible source of knowledge, and I will prove to all of you that it is possible to publish a multiplayer game made from scratch because nobody belive in my web socket serveur, but I know that it will be possible because I saw all the progress i've made !
no ones saying its not possible. Networking frameworks obviously exist, and were made from scratch. And i mean this in the nicest way possible, no one here really cares enough to be "proven wrong" on it because this isnt a matter of right/wrong.
We are saying this is a foolish journey to take if your goal is to actually publish a game, no one is saying it cant happen.
This system of mine adds an item into an inventory system. It works perfectly fine in almost every scenario except this one where I add an item to a system before I spawn in the ui slots using createlootslots()
It has the itemdata in the slot correctly as well as the correct tooltip. No null references. The image component that is refereced is the only thing failing to update. During runtime in the game I can even have the player grab the item and move it to his inventory where the image properly displays again.
The images with the axe shows its tool tip and the slot ui, this is how it proerply looks. the other images with the feather are all fine as well except the image component fails to change and just says none.
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
public void UpdateUISlot(InventorySlot slot) {
// Debug.Log("Updating ui slot");;
OnSlotUpdated?.Invoke(requiredItemType);
if (slot.itemdata != null) {
// Debug.Log("image null: " + (slot.itemdata.image == null));
image.sprite = slot.itemdata.image;
image.color = Color.white;
// Debug.Log($"Trying to update slot for {slot.itemdata.name}");
toolTipTrigger.SetText(slot.itemdata.name, slot.itemdata.description);
} else {``` This is the part that mostly trips me up as it correctly changes the tooltip and the sprite and the itemdata is correct as well. the image is not null if i remove the log statement. This works perfectly fine in most other scenarios too
It would be useful to see more of whatever scripts are the principal of the paste you've shared, ideally with each file as a separate paste and using a website like https://gdl.space - pastebin is sort of bloated and ad-riddled.
Readers can probably sort out the file divisions and derive the types of the fields and such by staring long enough, but that extra effort often drives would-be answerers away
I'm trying to link a script in unity to an external DLL with an asmdef and it just won't connect no matter how I set it up, keeps giving me this error whenever the script is enabled
The referenced script (Unknown) on this Behaviour is missing!
The referenced script on this Behaviour (Game Object 'Armour Module') is missing!
The referenced script on this Behaviour (Game Object '<null>') is missing!
The referenced script (DW.ArmourModule) on this Behaviour is missing!
The referenced script on this Behaviour (Game Object 'Armour Module') is missing!```
The class names and namespace all match and it should work, has anyone got any ideas?
I can provide screenshots of whatever's needed, just don't want to flood the chat
Is it a MonoBehaviour defined in the dll?
It is
I have a stub in unity with just 5 empty functions and a coroutine, all the code is in the DLL
Is the dll configured properly? And referenced if you're using assembly definitions?
Unity vs the DLL. It's worked before in the past but just won't link
This DLL hasn't worked* Other projects
The DLL should be configured just fine, what're the prerequisites? I don't remember doing much to other DLLs
And no, it's not referenced via the asmdef, I'm only referencing two DLLs in there
The game loads all the DLLs so it's not needed if I'm not referencing stuff in unity (hence the stub)
I don't think stubs are a thing in C#?π€
If you have 2 classes with the same name in the same namespace, they would just conflict and cause a compile error.
The errors you were getting indicate that the reference/guid in the GameObject metadata was pointing to a script/class that doesn't exist anymore.
how could i rotate feet like this procedurally using ik when they are to far behind the player
The game I'm making stuff for has done that for everything in the project
Well, I don't have access to your project so can't really comment on that.
All I can say is that logically thinking it shouldn't work.
I finally was able to create a decent Perlin Noise Terrain generator with serialized chunks π
I've attacked this problem multiple times but finally got it just right. Super excited
Hiya - There's some stuff I want to execute in Start() when the scene is being loaded but I don't want it executed when the same object is being instantiated programatically after the scene has loaded. Is there a good way to check why Start is being called withour using reflection to look at the call stack or something weird
There's lots of ways but one of the best ways is to just not use Start. Or at least not on that script. Use a custom function that you run from some kind of bootstrapper object in the scene's Start
I had considered that, but was hoping for a self-contained way so my sceneManager didn't need to know about these types of objects.
e.g.
pubic class BootStrapper : MonoBehaviour {
foreach (MyScript ms in FindObjectsOfType<MyScript>()) {
ms.Initialize();
}
}```
But if that's "approved", then I'll do it that way π
it doesn't need to
not sure what "approved" means
I didn't want BootStrapper to know about all of the different types like MyScript.
use an interface
I preferred to just handle it all in MyScript without creating another dependecny
yah - that feels better
with the interface
I'll go that route. Thanks!
int i = 0;
for (i = 0; i < PlayerInputs.PlayerControls.Length; i++)
{
optionsButtons[i].transform.parent.GetComponent<Button>().onClick.AddListener(() => ChangePlayerControls(i));
}
I'm trying to add a listener to a set of buttons using some code to automate the process, however onClick.AddListener() always fails
public void ChangePlayerControls(int keyToChange)
{
optionsButtons[Array.IndexOf(PlayerInputs.PlayerControls, keyToChange)].text = "Awaiting Input";
StartCoroutine(ReadInput((PlayerControlMap)keyToChange));
}
here is the called function for reference
classic variable capture situation
for (int i = 0; i < PlayerInputs.PlayerControls.Length; i++)
{
int x = i;
optionsButtons[x].transform.parent.GetComponent<Button>().onClick.AddListener(() => ChangePlayerControls(x));
}
Still fails to add the listener to the button
what do you mean it fails to add the listener
I mean it fails to add the listener, there's literally nothing there when I check in inspector
the onClick list is empty
If it is important, the buttons are disabled when I add listeners to them
well yes, you won't see listeners added via the AddListener method in the inspector, the inspector only shows persistent listeners (which you wouldn't be adding at runtime)
have you actually done anything to confirm whether this code is working? or are you just using the inspector and making assumptions?
okay nvm it does
I had literally no idea that was a thing
good to know
If I modify the emission of a material by lerping the values instead of the material on a renderer, will it change session wide?
Like how It's working in the scene now, instead of just changing one
Yes. It would affect all the objects sharing the same material
can an event return a value?
no but there are alternatives like delegate w return type , or event callback method
Can you clarify if you mean pass a value via the event, to be received by the subscriber, or return it to the point it is invoked?
Where can I find material about the latest version of ECS? ( Other than Docs)
why does this happen when changing the value of the base color through script? if i nudge the colour afterward it properly updates and removes this weird glow (the base color is not actually white either, as seen if i open the base map color changer window)
People in #1062393052863414313 would know best
Hi good day ya'll i just wanna ask is it possible to make a custom serializable class that be checked if its null? like example a weapon class which is under a character class(both serializable) to check if player has weapon or null?
Cause what happens is that weapon class under character class seems to be already instantiated.
How are you setting the color in the script?
if you have either of these objects as a serialized field on a monobehaviour then unity will have created an instance using its default values to serialize as part of the monobehaviour's data
Im guessing i have to make a custom editor gui for it to be displayed as null?
the inspector cannot display a null value. so yes, you'll need to write a custom editor to handle null if you want it to be null in the inspector
tried both GetComponent<MeshRenderer>().material.color and SetColor("_BaseMap", col"), same result
I see but then i can just do Character.weapon = null; right?
I was mostly just wondering if maybe you were using 0-255 values instead of 0-1
oh it needs to be 0-1? 
i guess that's why it's a float instead of an int lol
originally had HEX codes but converted them to RGB
new Color(22, 93, 200) << one of the colours i use
you need Color32 to do that
hmmm well it was set to 0-255 actually
it's like you didn't even read the page i linked
admittedly i saw the image and thought it'd be a quick fix but yeah no i read it now
thank you
yea that about fixed it, thank you y'all π dont really work with colours too often
On a corollary, why doesn't Color complain about out of range arguments, anyway? π€
Is it a valid use if you are aware of repercussions (despite being undocumented)? Or maybe it is considered too trivial to waste a runtime check on?
yeah HDR colors are supported and those go out of that 0->1 range
Ahh alright, that makes sense π
actually works tho in the inspector it loads the default values of the class 
yes, because the inspector cannot display null as i've already said
Thank2 i'll get a workaround on this 
you could just not serialize that field. or if it must be serialized and you want a simple way to ensure it is valid, give it a bool property that must be true when it has been assigned a valid instance
is there an efficent way to know when an LOD change occurs?
Whatβs your goal?
async load and unload resources based on an LOD2 change, mesh and textures
very limited memory
Might be more effective and controllable if you make a custom chunk-based streaming system. LOD uses distance to camera or renderer bounding volume size relative to view to switch levels.
Have you used CullingGroup API?
If I call a static function on a MonoBehavior, will It update every instance of that component or just one?
If not, is there a way to update every instance of a MonoBehavior from one main, and seperate script?
Googles results were.. Confusing to say the least π¦
A static method does not have access to instance variables
I'd use events for something like this
Oh good idea actually..
Yeah I see no reason why that wouldn't work for my use case π
Thanks!
Put them in a list and do a for loop over it
A static function has nothing to do with any instances
Hey, I'm having an issue with my 3D character rig in Unity. I've tried to fix it, but the problem persists. It gets into a weird pose whenever I go into play mode. (IΒ΄m using Animation rigging for the ik solution)
Sorry
does your company has a extended monobehaviour and is it worth it?
The alternative is... not using Unity I guess?
extending MonoBehaviour is the way to make scripts.
yeah i dont mean it like that some company's has a monobehaviour like (company)MonoBehaviour : MonoBehaviour\
so it extends monobehaviour and you can set a function like reset a transform in it
It's worth it ... if it makes sense for you to do it Β―_(γ)_/Β―
An extension function would be a much better way to do that.
yeah that wasnt a good example
but i was intressted if someone had a personal experience with it
I've never needed it π€·ββοΈ I've seen some people do it and their use-cases didn't seem all bad at the time (some 2 years ago), but I don't remember what exactly those were
I'd say - don't extend unless you have an actual use for that... you can always refactor it later on, if really necessary π€·ββοΈ
so i have another script for player rotating but the problem is that because in the editor i have made the XRotateTo and the YRotateTo 0
its not turning
soo make them not 0 in the editor
no matter how much i change them nothing happens
prove it
i made it one
ok i will send a video of without dotween vs with
the problem is that dotween only works in the start so it doesnt care what else happens
what is this suppsoed to be doing?
what are we comparing to?
Whjat does the other code do?
yes, you only wrote the dotween thing in Start, so it will only happen once there
rotate the player 180 degrees on the y axis
when it gets a D or right arrow input
Start() doesn't handle input
the DOTween code you shared makes no attempt to handle input
Hello, would anyone happen to know the method for realistic 2D rope swing physics? What I currently have is the player attachment to the rope, but I cannot seem to get the physics right. For now, it applies an impulse in the direction we're pointing (just once, when we change direction, e.g if the last direction was left and we press right it applies a force towards the right) but the physics aren't right at all. I'd like something realistic, where we have to swing multiple times left and right to accumulate velocity. How would I do that correctly? Already looked up on youtube, but the only good swinging physics didn't explain how they did it.
Adding force continuously as a button is held down is how i'd do it
if you make it a small force the player will have to swing back and forth to build up momentum
that's what I had way before, but since the force is continuous the rope doens't fall back after reaching the current max allowed by the current energy
then your force was too high
it needs to be too weak to overcome gravity on its own
yeah that's true
I think also one error I made was to apply the force only to the right, when it should also be slightly up, right?
i guess I would apply it to the cross product of the direction from the pivot to the player and forward. Basically along the tangent of the circle
I'm wondering if anyone can help me make a certain area foggy/dark? instead of the whole map
volumetric fog?
Whats that?
well it's... what you're asking for I think?
something like this
oh well do you know how i can add it?
that depends on which render pipeline you're using
basically you should google:
Unity HDRP Volumetric Fog
or
Unity URP Volumetric Fog
or
Unity Built In Volumetric Fog
depending on which pipeline you're using
alright
I'm trying to make a system where you can play a video and once youve watched the video, you get resurrected.
The issue im facing is that the first 2 seconds of video have distorted audio. The original file doesnt have this distortion and i think it's most likely since it's loading the video from a url.
Is there a way in Unity's VideoPlayer to wait until the first few frames of the video are ready to be played?
I think this would fix my initial distorted audio.
Here's the code i've tried and frameReady doesnt work for urls i think.... unless maybe i need to Play and pause it first to start the loading process and then wait for frameReady to resume playing.
Note that lambdas subscribed to events += () => { } cannot be unsubscribed with -= by using a lambda of the same signature. Your two un-subscriptions from inside the lambdas do nothing.
If you need to unsubscribe, make full methods
(the two pairs of lambdas are compiled to different methods - the -= operator will see them as different)
Guys, give me docs and stuff i will need, to integrate and make a 3RD Perspective player 3d movement, i have made good progress in my game, i wanna learn how to integrate camera and player rotation wiht mouse, and how to make Rigid Body add force code integrated with player's position, view and mouse movement
!docs
I couldnt find what i needed
I tried this
cine machine cant be integrated wiht physics, rigidbody
only character movement, or character controller
what
i forgot
Like When i turn, or rotate my camera
and press W (front key)
it will go front on litreral X-Axis
what does that have to do with Cinemachine ?
rather than front as in where player is looking
or physics
Look
for Rgid body
i have to do
Addforce (axis_
it has nothing to do with rigidbody
sounds like u have local/ world mixed up
Listen
you picked the wrong direction
or your character controller has the wrong orientation
please type in full sentences
make a full sentence please before you hit enter
ffs type in full sentences @swift falcon
π stop bro
im not reading any of that 1 word stuff so please retype ur question
how can i make it so that Rigid Body adds force to the direction of camera or player rather then specific Vector3 axis
use Camera.forward
wdym
Camera.transform.forward
AddRelativeForce
or taht ^
that wont use rigid bodies physiscs
dude its a direction
yes.. u still use RB.ADDFORCE
ok ill try it
π
direction relative to the camera's forward (blue arrow)
This is too much to absorb at once
well slow down
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
well do it until you understand each differnce
and cinnemachine
also stop typing like that
mb gang, its a habit
ur going to get warned if u continue..
well just before you hit enter, read back the sentence and if it makes sense send it
in a nutshell what does relative force do
β
I am going to refuse to help you until you learn to communicate like an adult
Vector3.forward would mean the local forward axis of the object
instead of the worlds forward
Im not even an adult π
ok so basiclly adds force in the direction that player is pointing
- on relative force
if you use AddForce(Vector3.forward); its gonna move forward in the worlds axis.. no matter what..
if u use AddRelativeForce(Vector3.foward); its going to use the forward axis of the object w/ the rigidbody

doing a character rigidbody is a pain